我正在建立一个允许某人签署交易的表格。我希望表单在提交后使用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;
    }

关于php - 提交表单后尝试创建php自动电子邮件,并使用HTML设置电子邮件样式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34884458/

10-12 12:36
查看更多