尝试在提交表单后创建 php 自动电子邮件,并使用 HTML 设置电子邮件样式


Trying to create a php auto email after a form has been submitted, and style the email with HTML

我正在构建一个允许某人注册交易的表单。我希望表单在提交后使用 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 );
    } 
}   
 ?> 

非常感谢。

最好的选择是使用 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;
    }