PHPMailer无法发送
我看到大多数PHPMailer问题都使用IsSMTP(),但我使用的是昨天发现的一个非常基本的示例,所以(在历史中似乎找不到链接),事实并非如此PHPMailer无法发送,php,phpmailer,Php,Phpmailer,我看到大多数PHPMailer问题都使用IsSMTP(),但我使用的是昨天发现的一个非常基本的示例,所以(在历史中似乎找不到链接),事实并非如此 require_once("class.phpmailer.php"); $email = new PHPMailer(); if (isset($_FILES['upload']['size'])) { echo 'file size: '.(basename($_FILES['upload']['size'])* 1024).'<
require_once("class.phpmailer.php");
$email = new PHPMailer();
if (isset($_FILES['upload']['size']))
{
echo 'file size: '.(basename($_FILES['upload']['size'])* 1024).'<br />';
if (move_uploaded_file($_FILES['upload']['tmp_name'], $target_path))
{
echo "The file ". basename( $_FILES['upload']['name'])." has been uploaded<br />";
$email->AddAttachment($target_path);
}
else
{
echo "There was an error uploading the file, please try again!<br /> ".basename($_FILES['upload']['error']);
}
}
else
{
echo "No file was found for the upload.<br />";
}
$email->To = "me@this.com";
$email->From = $email_from;
$email->FromName = $first_name;
$email->Subject = "Query from website";
$email->Body = $email_message;
//echo "mail built...<br />";
if (!$email->Send())
{
echo "Mailer error: " . $email->ErrorInfo;
}
这似乎没有触发它发送。也没有任何错误报告
编辑
结果是出现了一个错误,我在一个奇怪的地方重定向了一个方向,这阻止了我看到它。错误如下:
$email->IsSMTP();
$email->Host = "localhost";
$email->Port = 465;
$email->SMTPAuth = true;
$email->Username = "bacon";
$email->Password = "4ndCh33se";
您必须提供至少一个不支持的邮件程序
如果要通过
smtp
发送邮件,需要设置smtp
用户名和密码以及其他设置
您还需要添加IsSMTP()
Gmail SMTP设置示例
$this->SwiftMailer->smtpType = 'tls';
$this->SwiftMailer->smtpHost = 'smtp.gmail.com';
$this->SwiftMailer->smtpPort = 587;
$this->SwiftMailer->smtpUsername = 'emailaddress@gmail.com';
$this->SwiftMailer->smtpPassword = 'gmailPassword';
$this->SwiftMailer->sendAs = 'html';
$this->SwiftMailer->from = 'sender@gmail.com';
$this->SwiftMailer->fromName = 'Sender Name';
$this->SwiftMailer->to = "receiver@anything.com";
$this->Email->sendAs = 'html';
除了你的,我还有以下几件。也许这有助于:
$email->IsSMTP(); // set mailer to use SMTP
$email->Host = "mail.webaddress.com"; // specify main and backup server
$email->SMTPAuth = true; // turn on SMTP authentication
$email->Username = "********"; // SMTP username
$email->Password = "********"; // SMTP password
我在class.phpmailer.php中没有做任何更改
试试这个
最初,IsSMTP()的添加似乎至关重要,并按照其他答案实现 然而,所有答案都未能解决谜题中缺失的一块 PHPMailer要求至少添加1个地址,如下所示。我在这里使用的地址与
To
属性中设置的地址相同:
$email->To = "me@this.com";
$email->AddAddress("me@this.com");
一旦这样做了,一切都很好。我想我最大的担心是没有错误。。。电子邮件没有发送,所以肯定会出问题,但它没有告诉我?令人不安。如果您有能力读取服务器日志,请尝试查看发生了什么。如果没有,请询问您的主机在我上次编辑(刷新问题)后会出现什么问题,我现在可以看到一个错误,但这并没有使它消失。请尝试编写错误的密码。然后等待一个错误。尝试将端口号更改为25或587。可能值得一提的是,我不能100%确定我使用的凭据是否正确。我想你搞错了。试着写一个错误的密码,并查找日志发生了什么+1来查找问题。但这听起来确实像是一个大问题。你有什么版本?这是最新版本吗?也许你可以制作一个测试用例并在phpMailer站点上发布一个bug报告。是的,这是最新版本。我下载它是为了在这个网站上使用。我甚至不确定AddAddress调用的真正目的是什么,如果您已经指定了收件人和发件人地址。。。
$email->IsSMTP(); // set mailer to use SMTP
$email->Host = "mail.webaddress.com"; // specify main and backup server
$email->SMTPAuth = false; // turn on SMTP authentication
$email->Port = 25
$email->SMTPSecure = "";
$email->Username = "********"; // SMTP username
$email->Password = "********"; // SMTP password
$email->To = "me@this.com";
$email->AddAddress("me@this.com");