PHPMailer:Don';我听不懂发件人的地址
我正在学习PHPMailer,我不明白为什么它需要电子邮件地址和密码PHPMailer:Don';我听不懂发件人的地址,php,email,smtp,phpmailer,Php,Email,Smtp,Phpmailer,我正在学习PHPMailer,我不明白为什么它需要电子邮件地址和密码 $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
它不是来自个人电子邮件,而是来自网站。我应该在这里放什么电子邮件?为什么?电子邮件地址是发送电子邮件的地址。需要验证才能发送邮件的SMTP服务器需要用户名和密码。电子邮件的工作方式是,第1方有一个电子邮件帐户,用于向第2方发送邮件。第1方可以是一个站点、一个人、一个脚本或其他东西,但它仍然需要有一个电子邮件帐户才能发送电子邮件
这是SMTP(简单邮件传输协议)的方式,您需要遵循该协议的定义才能发送邮件。无需提供密码-
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.example.com"; // SMTP server
$mail->From = "example@gmail.com";
$mail->AddAddress("example@gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
您正试图使用
SMTP
发送电子邮件,执行此操作时,您需要使用有效的用户名和密码登录到SMTP
服务器。您可以更改此行$mail->isSMTP()代码>至$mail->isMail()
通过内置的邮件函数发送。因此,如果我将其更改为ismail()
我可以将密码和用户名以及所有内容留空?如果您使用isMail
您不需要所有与SMTP相关的设置,但它将使用PHP配置设置为使用的任何“发件人”地址,或者返回默认地址,可能类似www-data@server123.example.com
。邮件必须来自某个地址,否则如果无法送达,邮件将无法返回到任何地方。如果使用开放式中继,则无需使用密码,但在所有其他情况下,您都需要密码。此外,您的代码基于一个过时的示例,并且正在使用PHPMailer的旧版本。