使用表单的批量电子邮件不起作用


Bulk Email using form not working

我正试图使用php从gmail发送批量电子邮件,其中from address、to address和message是从表单中设置的。但它不起作用。。显示错误

Mail.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>

Index.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.

有人请帮我解决这个问题。我不知道问题出在哪里。

Cargo cult编程:

$mail->SetFrom("$_POST('from')","$_POST('from_name')");

应该只是

$mail->SetFrom($_POST['from'], $_POST['from_name']);

请注意使用了[]而不是(),并且在这些单个值周围使用了LACK"引号。

您必须修复脚本中执行这种错误数组引用的每一行代码。