I am new to PHP. I was trying to send myself a sample e-mail through PHPmailer. I am using gmail’s smtp server. I am trying to send a sample mail from my gmail account to my yahoo account. But I am getting the error : Mailer Error: SMTP connect() failed.
Here is the code :
<?php require "class.phpmailer.php"; $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = "ssl://smtp.gmail.com"; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "myemail@gmail.com"; // SMTP username $mail->Password = "mypassword"; // SMTP password $webmaster_email = "myemail@gmail.com"; //Reply to this email ID $email="myyahoomail@yahoo.in"; // Recipients email ID $name="My Name"; // Recipient's name $mail->From = $webmaster_email; $mail->Port = 465; $mail->FromName = "My Name"; $mail->AddAddress($email,$name); $mail->AddReplyTo($webmaster_email,"My Name"); $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML $mail->Subject = "subject"; $mail->Body = "Hi, This is the HTML BODY "; //HTML Body $mail->AltBody = "This is the body when user views in plain text format"; //Text Body if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; } ?>
I am using WAMP server on a Windows 7 64-bit machine. What could be the prob?
Please help me solve this. Thanks!
Advertisement
Answer
You need to add the Host
parameter
$mail->Host = "ssl://smtp.gmail.com";
Also, check if you have open_ssl
enabled.
<?php echo !extension_loaded('openssl')?"Not Available":"Available";