PHPMailer使用我的服务器电子邮件发送消息
正如本文所述,PHPMailer使用我的服务器电子邮件发送消息,而不是实际发件人的电子邮件。 例如: 发件人:sendernamemyservername@server.com 发件人电子邮件未显示在“发件人”部分中 这是我的密码PHPMailer使用我的服务器电子邮件发送消息,php,mysql,email,phpmailer,Php,Mysql,Email,Phpmailer,正如本文所述,PHPMailer使用我的服务器电子邮件发送消息,而不是实际发件人的电子邮件。 例如: 发件人:sendernamemyservername@server.com 发件人电子邮件未显示在“发件人”部分中 这是我的密码 $result = mysql_query($insert_query, $connection) or die(mysql_error()); if($result) { require_once('../se482/class.php
$result = mysql_query($insert_query, $connection) or die(mysql_error());
if($result)
{
require_once('../se482/class.phpmailer.php');
//$mail->SMTPDebug = 3; // Enable verbose debug output
//$mail->IsSMTP(true);
$mail = new PHPMailer; // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemail@gmail.com'; // SMTP username
$mail->Password = 'mypassowrd'; // SMTP password
$mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->CharSet = 'UTF-8';
$mail->Encoding = '8bit';
$mail->addAddress('myemail@gmail.com'); // Add a recipient
$mail->setFrom($email, $name);
//$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
$mail->isHTML(true); // Set email format to HTML
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->From = $email;
$mail->Subject = 'Here is the subject';
$mail->Body = $comment;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->Send();
$mail->SmtpClose();
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
$mail->from
被设置为$email
,这在任何地方都没有定义。您必须包括class.smtp.php
以及使用smtp
。同时取消注释/$mail->isSMTP(true)代码>
如文档中所述,为了避免出现这种情况,您只能包含autoloader类,该类为phpmailerautoad.php
更新代码
$result = mysql_query($insert_query, $connection) or die(mysql_error());
if($result)
{
//require_once('../se482/class.phpmailer.php');
// require_once('../se482/class.smtp.php');
//or
require_once('../se482/PHPMailerAutoload.php');
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(true);
$mail = new PHPMailer; // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemail@gmail.com'; // SMTP username
$mail->Password = 'mypassowrd'; // SMTP password
$mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->CharSet = 'UTF-8';
$mail->Encoding = '8bit';
$mail->addAddress('myemail@gmail.com'); // Add a recipient
$mail->setFrom($email, $name);
//$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
$mail->isHTML(true); // Set email format to HTML
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->From = $email;
$mail->Subject = 'Here is the subject';
$mail->Body = $comment;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->Send();
$mail->SmtpClose();
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
更新
您还可以在get\u auth\u token.php
中添加您的app
凭证,如gmail使用文档中所述。下面是链接删除/$mail->IsSMTP上的注释(true)
若要使用您拥有的smtp设置,如果我将其删除,则会出现以下错误:致命错误:对非对象调用成员函数IsSMTP(),将其放在下面$mail=new PHPMailer代码>我收到此附加错误:无法发送邮件。邮件程序错误:SMTP connect()失败。hmmm。我假设你的gmail的用户名
和密码
是正确的?没有定义,但我没有复制此处的全部代码抱歉,我如何包含该类并使用smtp?仍然收到相同的错误:邮件无法发送。邮件错误:smtp connect()失败您是否使用phpmailerautoad.php
?