phpgmailbulk-mail

Bulk Email using form not working


I am trying to send bulk email from gmail using php in which from address,to address and message are set from a form. But it is not working..shows error

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>

it shows the follwing error:

Invalid address: Array('from')
Invalid address: Array('from')
Invalid address: Array('to')
Mailer Error: You must provide at least one recipient email address.

Someone please help me to solve this problem. I am not getting what the problem is.


Solution

  • Cargo-cult programming:

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

    should probably just be

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

    Note the use of [] instead of (), and the LACK of " quotes around those single values.

    You'll have to fix up every line of code in your script where you're doing this sort of bad array referencing.