0

我正在尝试使用 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.

有人请帮我解决这个问题。我不明白问题是什么。

4

1 回答 1

0

货物崇拜编程:

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

应该只是

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

请注意使用[]代替(),以及这些单个值周围缺少"引号。

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

于 2013-07-31T18:13:01.987 回答