使用表单无法正常批量发送电子邮件

时间:2013-07-31 18:10:55

标签: php gmail bulk-mail

我正在尝试使用php从gmail发送批量电子邮件,其中从地址,地址和消息都是从表单设置的。但它不起作用..显示错误

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.

有人请帮我解决这个问题。我没有得到问题所在。

1 个答案:

答案 0 :(得分:0)

货物崇拜节目:

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

应该只是

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

请注意,使用[]代替()" LACK 引用这些单个值。

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