Send two different emails after form submission

2019-09-03 01:35发布

问题:

When a user submits a form, I want one email to come to me with the form fields and a separate email to be sent to the user confirming their submission (two separate emails with different content).

I tried the following form, but only the first email is generated. The second email is never received.

<?php
$url = "http://www.example.com";

$to = 'info@example.com';
$subject = 'Subject';
$headers .= "From: info@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message .= "Content of Message 1";
mail($to, $subject, $message, $headers);

$message = ""; 

$to = $_POST['email'];
$subject = 'Subject';
$headers .= "From: info@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message .= "Content of Message 2";
mail($to, $subject, $message, $headers);

$message = "";

echo '<META HTTP-EQUIV=Refresh CONTENT="1; URL='.$url.'">';

?>

What would prevent the second message from sending?

回答1:

Change the variable names,while $to and $subject are overwritten for the second email the concatenating variables..keep concatenating into a double mess.



回答2:

Just do

$to = "info@example.com;$_POST[email]"


标签: php forms email