December 6, 2010
Tonight a friend asked me to help him to send an email with PHP as soon as possible. Right now I utilize SwiftMailer but the fastest way was with PHPMailer. Almost two years ago I utilized this mail library. I've got the code in a project but I delete it 3 months ago ... Yes, yes, I know, I should not have done that. After an hour trying to send the email I promised myself not to pass for this situation again in the future, then here are the steps to send an email with PHPMailer using a gmail account.
Here is the link to download PHPMailer.
Code mail.html"_mcePaste" class="mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">https://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/
$mailer = new PHPMailer();
$mailer->SMTPAuth = TRUE;
$mailer->SMTPSecure = "ssl";
$mailer->Host = "smtp.gmail.com";
$mailer->Port = 465;
$mailer->Username = "[email protected]"; // Change this to your gmail adress
$mailer->Password = "**********"; // Change this to your gmail password
$mailer->From = "[email protected]"; // This HAVE TO be your gmail adress
$mailer->FromName = "Works!!"; // This is the from name in the email, you can put anything you like here
$mailer->Body = "Works!!";
$mailer->Subject = "This works!!!";
$mailer->AddAddress("[email protected]", "Jonathan"); // This is where you put the email adress of the person you want to mail
$mailer->AddAddress("[email protected]", "Karla");
$mailer->AddAddress("[email protected]", "Sano");
echo "Message was not sent";
echo "Mailer Error: " . $mailer->ErrorInfo;
echo "Message has been sent";
This was the step that took me 40 mins... yeah a line of code as always ... the questions were where? and why?
Where? in php.ini (that uses the Apache)
Why? to correctly authenticate your account.
Then, in your php.ini you must uncomment the following line:
Then save the file and restart the server.
Now browse: https://localhost/mail.html"crud_edit">