我正在尝试配置PHPMailer我已经上传了1个文件,即class.phpmailer.php,并使用此内容创建了另一个php文件:
<?php
require('class.phpmailer.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 = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail@gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom("the same email address");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("the same email address");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
我根本没有得到任何成功消息或失败消息。 http://www.mawk3y.net/mailtest/test.php
答案 0 :(得分:2)
问题在于require方法。
首先必须提取phpMailer存储库的所有文件。
而不是写
require('class.phpmailer.php');
您需要包含PHPMailerAutoload.php文件提取的路径。您可以将其替换为。
require('path-of-extracted-folder/PHPMailerAutoload.php');
如需更多参考,您可以访问它的GitHub链接
答案 1 :(得分:1)
所有答案现在都已过时。最新版本(截至2018年2月)不再具有自动加载功能,PHPMailer应该按以下方式初始化:
<?php
include_once(FCPATH.'PHPMailer/src/PHPMailer.php');
include_once(FCPATH.'PHPMailer/src/SMTP.php');
$msj="My complete message";
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
//authentication SMTP enabled
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
//indico el puerto que usa Gmail 465 or 587
$mail->Port = 465;
$mail->Username = "xxxxxx";
$mail->Password = "xxxx";
$mail->SetFrom("xxxxxx@xxxxx.com","Name");
$mail->AddReplyTo("xxx@xxx.com","Name Replay");
$mail->Subject = "Test";
$mail->MsgHTML($msj);
$mail->AddAddress("xxxxxx@xxxxx.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
答案 2 :(得分:0)
我有同样的问题,但我解决了。这是我编码的方式
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
// Set PHPMailer to use the sendmail transport
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'abc@gmail.com'; // SMTP username
$mail->Password = 'abc'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Set who the message is to be sent from
$mail->setFrom('abc1@gmail.com', 'First Last');
//Set an alternative reply-to address
//Set who the message is to be sent to
$mail->addAddress('abc@gmail.com', 'Shehan');
//Set the subject line
$mail->Subject = 'Test Mail';
$mail->Body = 'This is Test Mail';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>