我设法通过我的 xampp 中的本地主机使用 phpmailer 库将消息发送到我的 gmail 帐户,但该消息显示了“root 用户”而不是 gmail 帐户设置为 $mail->SetFrom 如何删除此“root 用户”并显示适当的名称。
<?php
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true;
$mail->Mailer = "smtp";
$mail->SMTPSecure = "tls";
$mail->Username = "georgediamei1234@gmail.com";
$mail->Password = "password";
$mail->Host = 'ssl://smtp.gmail.com'; // SMTP server
$mail->Port = 465;
$mail->FromName ='georgediamei1234@gmail.com';
$mail->AddAddress("nowtonkhurai@gmail.com");
$mail->Subject = "";
$mail->Body = "Hello, <b>Is photo attached</b>!\n\n This message uses HTML entities!";
$mail->addStringAttachment("$string","08DsAlg.pdf", "base64","application/pdf");
if($mail->send()) {
echo "Email sent";
} else {
echo 'Not send '.$mail->ErrorInfo;
}
?>