我尝试过这么多不同的教程试图让它工作但无济于事。这是我使用的代码,目前它的工作方式非常完美,除非我嵌入图像。嵌入图像后,就不会收到电子邮件。
<?php
$field_website = $_POST['cf_website'];
$field_name = $_POST['cf_name'];
$field_age = $_POST['cf_age'];
$field_email = $_POST['cf_email'];
$field_cell = $_POST['cf_cell'];
$field_tutor = $_POST['cf_tutor'];
$field_instrument = $_POST['cf_instrument'];
$field_lesson_type = $_POST['cf_lesson_type'];
$field_no_of_lessons = $_POST['cf_number'];
$field_amount_due = $_POST['cf_amount'];
$field_ref_num = $_POST['cf_ref_num'];
$field_booking_date = $_POST['cf_booking_date'];
$field_start_time = $_POST['cf_start_time'];
$field_end_time = $_POST['cf_end_time'];
$field_booking_date2 = $_POST['cf_booking_date2'];
$field_start_time2 = $_POST['cf_start_time2'];
$field_end_time2 = $_POST['cf_end_time2'];
$field_booking_date3 = $_POST['cf_booking_date3'];
$field_start_time3 = $_POST['cf_start_time3'];
$field_end_time3 = $_POST['cf_end_time3'];
$field_booking_date4 = $_POST['cf_booking_date4'];
$field_start_time4 = $_POST['cf_start_time4'];
$field_end_time4 = $_POST['cf_end_time4'];
if (empty($field_name) && empty($field_email) && empty($field_cell) && empty($field_tutor)) {
echo 'Please fill in all required fields';
return false;
}
else{
//process the rest of the form
}
if($field_website != ''){
echo "Submission Sent - Thank you!";
return false;
}
else{
//process the rest of the form
}
$mail_to = 'bookings@test.com';
$subject = 'Student Booking';
$headers = "From: " . strip_tags($field_email) . "\r\n";
$headers .= "Reply-To: ". strip_tags($field_email) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body_message = '<html><body style="font-family:calibri,sans-serif; font-size:18px">';
$body_message .= '<h2 style="font-weight:600; font-size:27px; border-bottom:dashed 1px #CCC; padding-bottom:10px;">Student Booking</h2>';
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Full Name:</strong> '.$field_name."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Age:</strong> '.$field_age."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">E-mail Address:</strong> '.$field_email."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Cellphone Number:</strong> '.$field_cell."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Tutor Name:</strong> '.$field_tutor."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Instrument to Learn:</strong> '.$field_instrument."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Lesson Type:</strong> '.$field_lesson_type."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Number of Lessons:</strong> '.$field_no_of_lessons."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Amount Due:</strong> R'.$field_amount_due."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Reference Number:</strong> #'.$field_ref_num."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Booking Date:</strong> '.$field_booking_date."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">Start Time:</strong> '.$field_start_time."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">End Time:</strong> '.$field_end_time."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">2nd Booking Date:</strong> '.$field_booking_date2."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">2nd Start Time:</strong> '.$field_start_time2."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">2nd End Time:</strong> '.$field_end_time2."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">3rd Booking Date:</strong> '.$field_booking_date3."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">3rd Start Time:</strong> '.$field_start_time3."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">3rd End Time:</strong> '.$field_end_time3."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">4th Booking Date:</strong> '.$field_booking_date4."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">4th Start Time:</strong> '.$field_start_time4."</p>\n"."\n";
$body_message .= '<p><strong style="color:#000; font-weight:600; ">4th End Time:</strong> '.$field_end_time4."</p>\n"."\n";
$body_message .= '</body></html>';
$autoTo = "$field_email";
$subject_auto = 'Booking Received!';
$headers_auto = "From: " . strip_tags('bookings@test.com') . "\r\n";
$headers_auto .= "Reply-To: ". strip_tags('bookings@test.com') . "\r\n";
$headers_auto .= "MIME-Version: 1.0\r\n";
$headers_auto .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$auto_body = '<html><body style="font-family:calibri,sans-serif; font-size:18px">';
$auto_body .= '<p>Dear '.$field_name."</p>\n"."\n";
$auto_body .= '<p>Thank you for booking at We See Musically! Confirmation of your booking details are shown below: '."</p>\n"."\n";
$auto_body .= '<p><strong>Tutor Name:</strong> '.$field_tutor."</p>\n"."\n";
$auto_body .= '<p><strong>Instrument Chosen:</strong> '.$field_instrument."</p>\n"."\n";
$auto_body .= '<p><strong>Lesson Type:</strong> '.$field_lesson_type."</p>\n"."\n";
$auto_body .= '<p><strong>Number of Lessons:</strong> '.$field_no_of_lessons."</p>\n"."\n";
$auto_body .= '<p>Please note that the amount due is R'.$field_amount_due.' and your reference number is #'.$field_ref_num.'. Please kindly make sure to use your reference number otherwise your booking will not be processed. Once payment has been received, your tutors full residential address as well as your booked dates and times will be emailed to you. '."</p>\n"."\n";
$auto_body .= "<p>We trust you'll have a great tutoring experience at We See Musically! "."</p>\n"."\n";
$auto_body .= '<img src="http://test.com/images/wsm-logo.png" ALT="We See Musically">';
$auto_body .= '</body></html>';
mail($autoTo, $subject_auto, $auto_body, $headers_auto);
mail($mail_to, $subject, $body_message, $headers);
?>
答案 0 :(得分:0)
发送电子邮件非常复杂,所以我建议您使用经过测试的库,而不是直接使用PHP的mail()
函数。
某些邮件服务使用非常旧的软件。他们可能会拒绝包含超过70个字符行的电子邮件(我已经看到过这种情况)或拒绝包含ASCII以外字符的电子邮件。这只是冰山的顶端,所以很难说你的具体信息有什么问题。
如果您要编写自己的邮件实现,首先应阅读一些相关的RFC,如PHP手册中提到的那些:
以下RFC可能有用:»RFC 1896,»RFC 2045,»RFC 2046, »RFC 2047,»RFC 2048,»RFC 2049和»RFC 2822。
或者您可以使用Zend\Mail
,PEAR::Mail
,SwiftMailer
或PHPMailer
等库,并依赖这些软件包的开发人员进行的测试。