pranshu82202 Posted July 16, 2011 Share Posted July 16, 2011 <?php require("class.phpmailer.php"); // path to the PHPMailer class $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Mailer = "smtp"; $mail->Host = "ssl://smtp.gmail.com"; $mail->Port = 465; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "[email protected]"; // SMTP username $mail->Password = "yourpassword"; // SMTP password $mail->From = "email address sender"; $mail->AddAddress("email address receiver"); $mail->Subject = "First PHPMailer Message"; $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer."; $mail->WordWrap = 50; if(!$mail->Send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } ?> I am using this code to send mails via smtp... But all the time i get the following error SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host. Please tell me what shuld i do.... Quote Link to comment https://forums.phpfreaks.com/topic/242146-mail-error-code-present/ Share on other sites More sharing options...
IrOnMaSk Posted July 20, 2011 Share Posted July 20, 2011 Pran, Did you edit the php.ini by putting that gmail server where it says smtp? search for smtp, it should be under mail function, and the one says smtp = ". put your code below after that equal sign and your port under neath it. ssl://smtp.gmail.com 465 And is there a reason why you have to use the phpmailer class? to me its much simpler to use the mail function. I've been sending out tons of email just using the mail function. let me know if it works Quote Link to comment https://forums.phpfreaks.com/topic/242146-mail-error-code-present/#findComment-1245170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.