PHPMailer send mail with array ( $_POST['email'] )

751 views Asked by At

Hi I have question about HTML and PHP array form. In the HTML form I ask 3 emails and send them to my database.

Someone knows how to make it work please? Thanks!

HTML FORM:

<form id="formulario" method="post" action="php/enviar.php" enctype="multipart/form-data">
<input type="email" name="email" required>
<input type="email" name="email1" required>
<input id="submit" type="submit" name="enviar" value="Send mail">
</form>

PHPMailer Part:

$para1  = $_POST['email'];
$para2  = $_POST['email1'];
$recipientes = array('[email protected]', '[email protected]');
foreach($recipientes as $email)
{
   $mail->AddAddress($email);
   print_r($email); //only test
}

Error:

Invalid address: emailemail
Invalid address: email1email1
You must provide at least one recipient email address.

Thanks, sorry for my bad english!

1

There are 1 answers

0
Abhinav On

First of all,I do not think you have implemented the PHPMailer the rght way.

Take a look at the PHPMailer github link for the simple example on how it is implemented.

1) You have to first include the PHPMailer class in your code

2) Then initialize the PHPMailer like $mail = new PHPMailer;. Have to set all the properties of the initialized object and then send mail.

You have mentioned about sending the datas to database although you have not provided any code of what you are trying to do