Sending email by using PHP and SMTP?
Hey can anyone help me by giving some code on how to send email by using PHP and SMTP? I have my own code but it has not been working properly please suggest some general views of code so that I can make out the coding according to my case or anyone who have been doing this can show me there coding to help me how you all have done it? Please help me guys as soon as possible any clue would be appreciated.
Re: Sending email by using PHP and SMTP?
Hello if you would have provided us with your code then it would have been more better so that would have tried to make out what has went wrong or tell us what error you are been displayed anyways jus check if your code has fshockopen is enabled if you are using it otherwise I have a solution just go through it and look out if it helps you
Code:
<?php
require_once "Mail.php";
$from = "<me.gmail.com>";
$to = "<sending to.yahoo.com>";
$subject = "Hello!";
$body = "Hi,\n\n What’s up with you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<mine.gmail.com>";
$password = "Password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $Username,
'password' => $Password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::is Error($mail)) {
echo("<p>" . $mail->get Message (). "</p>");
} else {
echo("<p>Message has been delivered!</p>");
}
?>
Just check this out if you get any clue enjoy coding.
Re: Sending email by using PHP and SMTP?
Hey, I think this would be working with several changes according to our requirement and as some changes in that SMTP server detail as it is been mentioned by you, you need to take care of that to I personally think you need to change that SMTP details to I have a little code to work with this SMTPconfig.PHP here is it
Code:
<? Php
$SmtpServer=”127.0.0.1”;
$SmtpPort=”25”;
$SmtpUser=”Username”
$SmtpPass=”Password”;
?>
change it and see if you are solved with your dought.
Re: Sending email by using PHP and SMTP?
Oh yes this is a good solution but I have my own solution which I have been using and it’s not having much difference but just a syntax difference I would like to share it with you so that if this solutions haven’t solved your problem might this one would be as same as yours and you can get through it
Code:
<?php
require_once "Mail.php";
$from = "senders name <name@myemail.com>";
$to = "sending to whom <name@targetemail.com>";
$subject = "what’s going on !";
$body = "Hello,\n\n how are you doing?";
$host = "mail.mailserver.com";
$username = "Username@myemail.com";
$password = "Password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host’ => $host,
'auth' => true,
'username' => $Username,
'password' => $Password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo ("<p>Message successfully sent!</p>");
}
?>
hope it finds you the way to get rid of your problem.
Re: Sending email by using PHP and SMTP?
Well I used this and it has worked to me friend I think this solutions are enough and I think working or going through different solutions and syntax would confuse you stick to the basic and go on try taking helps from the professors you got around because they would be able to go through your coding and they would help you in much better and no need to have n number of attempts because I feel personally that is a waste of time just going through different number of attempts all the time this codes are perfect according to me it did worked to me so just make several changes and get it done.