San*_*San 1 php gmail phpmailer
我正在尝试使用PHPMailer_V5.1通过gmail发送电子邮件.
得到以下错误,
SMTP - >错误:无法连接到服务器:无法找到套接字传输"ssl" - 您是否忘记在配置PHP时启用它?(41961176)SMTP错误:无法连接到SMTP主机.
以下是PHPMailer下载附带的代码,我刚修改了必填字段,
<?php
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "santosh1984naidu@gmail.com"; // GMAIL username
$mail->Password = "********"; // GMAIL password
$mail->AddReplyTo('santosh1984naidu@gmail.com', 'First Last');
$mail->AddAddress('santosh1984naidu@gmail.com', 'John Doe');
$mail->SetFrom('santosh1984naidu@gmail.com', 'First Last');
$mail->AddReplyTo('santosh1984naidu@gmail.com', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment('images/phpmailer.gif'); // attachment
$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
?>
Run Code Online (Sandbox Code Playgroud)
根据错误,似乎在PHP中未启用SSL.在我的头脑中,我相信你需要取消注释
extension = PHP_openssl.dll
在你的php.ini文件中
如果已在您的系统上设置SSL,以下应该可以帮助您安装SSL:
http://us2.php.net/manual/en/openssl.installation.php
| 归档时间: |
|
| 查看次数: |
7960 次 |
| 最近记录: |