通过单键提交将PHP邮件发送到不同的电子邮件

时间:2015-03-16 08:16:03

标签: php html forms

对于我的某个网站,我使用的是联系表单,下面给出了PHP代码。 如果通过HTML表单发布详细信息,我将收到邮件" mail@xyz.com"。

<?php
if(!isset($_POST['submit']))
{
    header('Location: error.html');
    exit;
}
$name = $_POST['name'];
$place = $_POST['place'];
$email = $_POST['email'];
$message = $_POST['message'];

$to = "mail@xyz.com";
$subject = "Through Contact form";


$email_body = "NAME:     $name\n".
              "PLACE:    $place\n".
              "EMAIL-ID: $email\n\n".
              "Message:  $message\n";

$to = "mail@xyz.com";

//Send the email!
mail($to, $subject, $email_body);


//done
header('Location: thank.html');
?>

我想要的是在单键提交中将相同的messgae发送到不同的邮件。 例如:

mail@xyz.com, 
info@abcd.com,  
contact@othersite.com.

1 个答案:

答案 0 :(得分:0)

使用以下代码。

<?php
if(!isset($_POST['submit']))
{
    header('Location: error.html');
    exit;
}
$name = $_POST['name'];
$place = $_POST['place'];
$email = $_POST['email'];
$message = $_POST['message'];

$emails = array("mail@xyz.com", "info@abcd.com" , "contact@othersite.com");

$subject = "Through Contact form";


$email_body = "NAME:     $name\n".
              "PLACE:    $place\n".
              "EMAIL-ID: $email\n\n".
              "Message:  $message\n";

$to = "mail@xyz.com";

//Send the email!

foreach ($emails as $to) {
mail($to, $subject, $email_body);
}

//done
header('Location: thank.html');

&GT;