即使在php.ini中设置openssl后,也无法使用PHPMailer发送邮件

时间:2013-08-08 13:38:43

标签: php

我在php中遇到电子邮件问题,我想给自己发邮件(只是为了测试),我想使用这个功能,以便用户可以通过网站向我发送反馈。

我在php.ini中启用了openssl,我在localhost和win7上使用了wamp server 2.0 plzzz帮助我,我是新来的PHP! 这是代码: -

<?php
require('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->SMTPDebug = 1;
$mail->Port = 587;
$mail->Host = 'mail.gmail.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'myid@gmail.com';                            // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'ssl';                   // Enable encryption, 'ssl' also accepted

$mail->From = 'myid@gmail.com';
$mail->FromName = 'AshiMailer';
$mail->AddAddress('myid.sbit@gmail.com', 'Josh Adams');  // Add a recipient
$mail->AddAddress('myid@gmail.com');               // Name is optional
$mail->AddReplyTo('myid@gmail.com', 'Information');
//$mail->AddCC('cc@example.com');
//$mail->AddBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
//$mail->AddAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->AddAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}

echo 'Message has been sent';

?>

1 个答案:

答案 0 :(得分:0)

使用这些设置

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