[英]Add e-mail and sender - PHP form
我有联系表。 我想将CC添加到电子邮件:abc@abc.de并更改电子邮件发件人。 目前,该服务器将我的服务器显示为发件人,我希望收到回复表单的用户。
你好。 我有联系表。 我想将CC添加到电子邮件:abc@abc.de并更改电子邮件发件人。 目前,该服务器将我的服务器显示为发件人,我希望收到回复表单的用户。
<?php
session_start();
//Ajax Questions Form
if(isset($_POST['email'])){
$name = $_POST['name'];
$email = $_POST['email'];
$arrival = $_POST['arrival'];
$departure = $_POST['departure'];
/// $adults = $_POST['adults'];
// $children = $_POST['children'];
// $room = $_POST['room'];
$requests = $_POST['requests'];
$to = 'contact@test.camp'; //Replace with recipient email address
$subject = 'Hotel Booking'; //Subject line for emails
$message = 'From: '.$name."\r\n".'Email: '.$email."\r\n".'Arrival: '.$arrival."\r\n".'People: '.$departure; //."\r\n".'Adults: '.$adults."\r\n".'Children: '.$children."\r\n".'Room: '.$room."\r\n".'Requests: '.$requests;
// Mail Functions
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message) or die('Error sending Mail'); //This method sends the mail.
echo "Your email was sent!"; // success message
}
}
//Contact Php Form
if(isset($_POST['contact_email'])){
$contact_name = $_POST['contact_name'];
$email = $_POST['contact_email'];
$contact_message = $_POST['message'];
$to = 'marek@gmail.com'; //Replace with recipient email address
$subject = 'Contact Form'; //Subject line for emails
$message = 'From: '.$contact_name."\r\n".'Email: '.$email."\r\n".'Message: '.$contact_message;
// Mail Functions
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // This line checks that we have a valid email address
mail($to, $subject, $message) or die('Error sending Mail'); //This method sends the mail.
}
}
?>
php邮件功能没有太多功能,请尝试使用类似PHPMailer的功能 ,该功能可让您发送更复杂的电子邮件
对于添加抄送或密件抄送或ReplyTo将标头添加到您的电子邮件结构中:
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'To: andreas<mail1@gmail.com>, thomas<mail2@gmail.com>';
$headers[] = 'From: from <from@gmail.com>\r\nReply-to: <ReplyTo@gmail.com>';
$headers[] = 'Cc: Cc@gmail.com';
$headers[] = 'Bcc: Bcc@gmail.com';
mail($to, $subject, $message, implode("\r\n", $headers));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.