我正在构建一个允许某人注册交易的表单。我希望表单在提交后使用php发送3封电子邮件;将表格的详细信息发送给我自己,一个将详细信息发送给提供交易的人,另一个将实际的交易确认和凭证发送给注册的人。
我遇到了一些问题,因为某些电子邮件地址在我测试时似乎没有接收或发送电子邮件(它适用于我的hotmail和gmail地址,但不适用于我自己的域名电子邮件地址)。我也无法弄清楚如何在发送的电子邮件中添加某种html样式。
如何设置这些电子邮件的样式并确保将它们发送到正确的电子邮件地址?
这是代码:
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$airline=$_REQUEST['airline'];
$position=$_REQUEST['position'];
$checkin=$_REQUEST['checkin'];
$attendance=$_REQUEST['attendance'];
$email=$_REQUEST['email'];
$terms=$_REQUEST['terms'];
if (($name=="")||($position=="")||($checkin=="")||($attendance=="")||($email==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
//email going to me//
else{
$from="From: Deal 1 Form Submission<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("myemail@test.com",
$subject,
$message="someones taken the deal: heres their info: <br> Name: $name\nAirline: $airline\nPosition: $position\nCheckin: $checkin\nAttendance: $attendance\nEmail: $email\n" );
echo "Email sent!";
}
//email going to the customer//
{
$from="From: me<myemail@test.com>\r\nReturn-path: $email";
$subject="Thank you for choosing this deal";
mail("$email", $subject, $message="thanks for choosing this deal!, please present this voucher when attending the restaurant", $from );
}
//email going to the partner//
{
$from="From: Me<myemail@test.com>\r\nReturn-path: $email";
$subject=" Great news! Someone has chosen your deal";
mail("partneremail@test.com",
$subject,
$message="Fantastic news, a customer has taken your deal! here's their info: Name: $name\nAirline: $airline\nPosition: $position\nCheckin: $checkin\nAttendance: $attendance\nEmail: $email\n
", $from );
}
}
?>
非常感谢。
答案 0 :(得分:0)
最好的办法是使用PHPMailer。这是一些通过gmail中继电子邮件的示例代码。您希望这样做的原因是为了避免来自服务器的电子邮件进入您的垃圾邮件箱。
$debug = true; // set it to false in production
$Mail = new PHPMailer();
if ($debug) {
// this allows you to see the details of the connection to gmail
$Mail->SMTPDebug = 4;
}
$Mail->isSMTP();
$Mail->Host = 'smtp.gmail.com';
$Mail->SMTPAuth = true;
$Mail->Username = 'your@gmail.com';
$Mail->Password = '[your-password]';
$Mail->SMTPSecure = 'tls';
$Mail->Port = 587;
$Mail->setFrom('from@address.com', 'John Smith');
$Mail->addAddress('to@address.com', 'Someone Else');
$Mail->addReplyTo('from@address.com', 'John Smith');
$Mail->addBCC('bcc@address.com', 'BCC Person');
$Mail->addAttachment('path/to/img/or/pdf/or/whatever/you/want/to/attach.pdf');
$Mail->Subject = 'Test Subject';
$Mail->Body = '<h1>Hi! This is an HTML format body'
$Mail->AltBody = 'Hi! Im just a text email in case HTML is not supported!';
if (!$Mail->send()) {
print $Mail->ErrorInfo;
return false;
} else {
return true;
}