0

I downlaoded a mailer file from https://github.com/PHPMailer/PHPMailer and tried to used in my program to send email, but it lead me to some error . first let have a look at the code

include 'PHPMailer-master/class.phpmailer.php';
include 'PHPMailer-master/class.smtp.php';

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "........@gmail.com";
$mail->Password = "*****";
$mail->SetFrom('.....@gmail.com');
$mail->Subject = "Test";
$mail->Body = "this the mail for subscription";
$mail->AddAddress('......@gmail.com');
 if(!$mail->Send())
 {
     echo "Mailer Error: " . $mail->ErrorInfo;
 }
 else
 {
     echo "Message has been sent";
 }
?>

after running this code i get the error message as:

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1546610735)SMTP Connect() failed. Mailer Error: SMTP Connect() failed.

please let me know the problem, as i have seen other post...but i did not get any hint

Anurag Singh
  • 727
  • 6
  • 10
  • 27
  • Why have you [asked this question again](http://stackoverflow.com/questions/18180327/unable-to-send-mail-in-php-using-mailer-class)... edit the previous question... – naththedeveloper Aug 12 '13 at 07:50

2 Answers2

0

Just replace

$mail->Host = 'smtp.gmail.com';

No need to specify the SSL here.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • now i get the error as: CLIENT -> SMTP: EHLO localhost CLIENT -> SMTP: STARTTLS Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in C:\xampp\htdocs\program\mailsending1\mailsending_v1\PHPMailer-master\class.smtp.php on line 254 CLIENT -> SMTP: quit SMTP -> ERROR: SMTP server rejected quit command: SMTP Connect() failed. Mailer Error: SMTP Connect() failed. – Anurag Singh Aug 12 '13 at 07:54
  • Have you removed the ; in the php.ini from this line ? `extension=php_openssl.dll` – Shankar Narayana Damodaran Aug 12 '13 at 08:08
  • Remove it , save the file and restart the xamp server. – Shankar Narayana Damodaran Aug 12 '13 at 09:08
0

for mailing with phpmailer use code like below

require_once('../class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->Subject    = "PHPMailer Test Subject via mail(), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";

// optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

You may get complete help from here

Synchro
  • 35,538
  • 15
  • 81
  • 104
Ripa Saha
  • 2,532
  • 6
  • 27
  • 51