我正在尝试使用 php 从 gmail 发送批量电子邮件,其中地址、地址和消息是从表单设置的。但它不工作..显示错误
邮件.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - GMail SMTP test</title>
</head>
<body>
<?php
date_default_timezone_set('Etc/UTC');
require '../Mail/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "username@gmail.com";
$mail->Password = "passwrd";
$mail->SetFrom("$_POST('from')","$_POST('from_name')");
$mail->AddReplyTo("$_POST('from')","$_POST('from_name')");
$mail->AddAddress("$_POST('to')","$_POST('from_name')");
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->MsgHTML("$_POST('message')");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
索引.php
<form action="mail.php" method="POST">
<div>
From:
<input type="text" name="from" />
Name:<input type="text" name="from_name" />
</div>
<div>
to:
<input type="text" name="to" />
Name:<input type="text" name="to_name" />
</div>
<div>
Message:
<textarea name="message"></textarea>
</div>
<input type="submit" value ="Submit"/>
</form>
它显示以下错误:
Invalid address: Array('from')
Invalid address: Array('from')
Invalid address: Array('to')
Mailer Error: You must provide at least one recipient email address.
有人请帮我解决这个问题。我不明白问题是什么。