簡體   English   中英

PHP將圖像嵌入表單

[英]PHP embed image into form

我嘗試了許多不同的教程來嘗試使它正常工作,但無濟於事。 這是我正在使用的代碼,除了嵌入圖像時,它目前可以正常運行。 嵌入圖像后,將不會收到電子郵件。

<?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);

?>

發送電子郵件非常復雜,因此我敦促您使用經過測試的庫,而不是直接使用PHP的mail()函數。

有些郵件服務使用的軟件確實很舊。 他們可能拒絕包含行數超過70個字符的電子郵件(我已經看到這種情況),或者拒絕包含ASCII以外字符的電子郵件。 那只是冰山一角,因此很難說出您的特定訊息出了什么問題。

如果要編寫自己的郵件實現,則應先閱讀一些相關的RFC,例如PHP手冊中提到的RFC:

以下RFC可能有用:»RFC 1896,»RFC 2045,»RFC 2046,»RFC 2047,»RFC 2048,»RFC 2049和»RFC 2822。

或者,您可以只使用Zend\\MailPEAR::MailSwiftMailerPHPMailer類的庫,並依靠這些程序包的開發人員進行的測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM