[英]PHPMailer works on one page but doesn't work on similar
EDIT: Somehow the code only works on the webserver and not on localhost, so there's your "fix". 编辑:不知何故,该代码只能在Web服务器上运行,而不能在localhost上运行,因此有您的“修复程序”。
So, my php code works as it should like this: 因此,我的php代码可以正常运行:
require 'PHPMailer/PHPMailerAutoload.php';
$nome = $_POST["nome"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$email = $_POST["email"];
$contacto = $_POST["contacto"];
$body = "<p>Mail recebido de: </p>" . $nome . "<p>Email:</p>" . $email . "<p> Contacto:</p>" . $contacto . "<p>Mensagem:</p>" . $message ;
$mail = new PHPMailer();
$mail->CharSet = "text/html; charset=UTF-8;";
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "the email";
$mail->Password = the password;
$mail->SetFrom('the email', 'Organizer');
$mail->Subject = "[ORÇAMENTO] " . $subject;
$mail->Body = $body;
$mail->IsHTML(true);
$mail->AddAddress("the email");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
$sucesso = 'Mensagem enviada com sucesso!';
}
this first script sends the email to itself, but even that doesn't work here ($mail->Send() = 1, still I don't receive the email): 这个第一个脚本将电子邮件发送给自己,但是即使在这里也不起作用($ mail-> Send()= 1,但我仍然没有收到电子邮件):
require '../PHPMailer/PHPMailerAutoload.php';
$body = "<p>Car(a) " . ${'user' . $i} . ",</p> <p> Foi lhe associado(a) uma nova ocorrência. Consulte-a em http://www.organizer.com.pt . </p>";
$mail = new PHPMailer();
$mail->CharSet = "text/html; charset=UTF-8;";
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "the email";
$mail->Password = the password;
$mail->SetFrom('the email', 'Organizer');
$mail->Subject = "Nova Ocorrência";
$mail->Body = $body;
$mail->IsHTML(true);
$mail->AddAddress($email);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
$sucesso = 'Mensagem enviada com sucesso!';
}
I have tested all the variables that I get from the database and so on and they are all correct, I just don't receive the email for some reason. 我已经测试了从数据库中获取的所有变量,等等,它们都是正确的,只是出于某种原因我没有收到电子邮件。 Anyone can help?
有人可以帮忙吗?
PS: Sorry some of this is in portuguese, I think the code is still perfectly understandable. PS:对不起,其中一些是葡萄牙语,我认为代码仍然可以完全理解。
"Doesn't work" is not a useful problem description. “无效”不是有用的问题描述。 On SO, detail is everything.
因此,细节就是一切。
It doesn't help that you've based your code on an obsolete & incorrect example and have not read the docs, and I suspect you are using an old version of PHPMailer too since it would have provided you with a link to relevant docs if it was a recent version. 如果您基于过时且不正确的示例创建了代码,并且没有阅读文档并没有帮助,并且我怀疑您也使用了旧版本的PHPMailer,因为它会为您提供相关文档的链接,如果这是最新版本。 So before anything else, get the latest version and read the docs .
因此,在获取其他任何内容之前,请先获取最新版本并阅读docs 。
As for specific problems: SMTPSecure = 'ssl'
with Port = 587
will not work. 至于特定的问题:
Port = 587
SMTPSecure = 'ssl'
将不起作用。 Port 587 is used for SMTP+STARTTLS, not implicit SSL, so set SMTPSecure = 'tls'
. 端口587用于SMTP + STARTTLS,而不是隐式SSL,因此设置
SMTPSecure = 'tls'
。
This is just wrong: 这是错误的:
$mail->CharSet = "text/html; charset=UTF-8;";
Your other script does it right: 您的其他脚本可以正确执行此操作:
$mail->CharSet = 'UTF-8';
If you're having trouble with something that has a debug option, enable it! 如果您遇到带有调试选项的东西,请启用它!
$mail->SMTPDebug = 2;
Increase that to 3 if you have initial connection problems. 如果您有初始连接问题,请将其增加到3。
I'd like to know where you got that example code so I can ask the authors to delete or update it; 我想知道示例代码在哪里,所以我可以要求作者删除或更新它。 having broken, obsolete examples lying around just wastes everybody's time.
摆弄破旧的例子只会浪费每个人的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.