使用phpmailer类 [英] use of phpmailer class
问题描述
require '../class.phpmailer.php';
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$body = file_get_contents('contents.html');
echo $body;
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->Username = "test@gmail.com"; // SMTP server username
$mail->Password = "1234567889"; // SMTP server password
$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo("rto@gmail.com","First Last");
$mail->From = "from@gmail.com";
$mail->FromName = "First Last";
$to = "toemail@gmail.com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
使用GMail,您的设置可能不正确;试试这些(正确的端口和SSL地址):
$mail->Port = 465; // set the SMTP server port
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->Username = "test@gmail.com"; // SMTP server username
$mail->Password = "1234567889";
或者,使用TLS:
$mail->Port = 587; // set the SMTP server port
$mail->Host = "tls://smtp.gmail.com"; // SMTP server
编辑:删除下面的这一行(您首先提供使用SMTP的设置,然后告诉它使用并发送通过sendmail,然后在配置中输入了错误的路径.只需坚持一项服务,使用具有上述设置(或下面的edit2)的SMTP并查看):
删除:
$mail->IsSendmail(); // tell the class to use Sendmail
Edit2::其他选项(如果第一个答案不起作用):
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
i m using phpmailer class for sending emails. i m geeting error "Could not execute: /smtp" the following code the code is below. can someone suggest me what is the problem.
require '../class.phpmailer.php';
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$body = file_get_contents('contents.html');
echo $body;
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->Username = "test@gmail.com"; // SMTP server username
$mail->Password = "1234567889"; // SMTP server password
$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo("rto@gmail.com","First Last");
$mail->From = "from@gmail.com";
$mail->FromName = "First Last";
$to = "toemail@gmail.com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
By using GMail, your settings might likely not be correct; try these (corrected port and SSL address):
$mail->Port = 465; // set the SMTP server port
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->Username = "test@gmail.com"; // SMTP server username
$mail->Password = "1234567889";
Alternatively, use TLS:
$mail->Port = 587; // set the SMTP server port
$mail->Host = "tls://smtp.gmail.com"; // SMTP server
Edit: Remove this line below (You first provide settings to use SMTP, then you tell it to use and send trough sendmail and you put a wrong path in configs. Just stick to one service, use SMTP with above settings (or edit2 below) and see):
Remove:
$mail->IsSendmail(); // tell the class to use Sendmail
Edit2: other option (in case the first answer don't work):
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
这篇关于使用phpmailer类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!