Я отправляю информацию на адрес электронной почты с помощью метода PHP native mail() прямо сейчас. Все остальное отлично работает, но часть стола беспокоит меня больше всего. См. Образец:Как вставлять таблицу html в тело сообщения электронной почты
Dear Michael Mao :
Thank you for purchasing flight tickets with us, here is your receipt :
Your tickets will be delivered by mail to the following address :
Street Address 1 : sdfsdafsadf sdf
Street Address 2 : N/A
City : Sydney State : nsw Postcode : 2
Country : Australia
Credit Card Number : *************1234
Your purchase details are recorded as :
<table><tr><th class="delete">del?</th><th class="from_city">from</th><th class="to_city">to</th><th class="quantity">qty</th><th class="price">unit price</th><th class="price">total price</th></tr><tr class="evenrow" id="Sydney-Lima"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Lima</td><td>1</td><td>1030.00</td><td>1030</td></tr><tr class="oddrow" id="Sydney-Perth"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Perth</td><td>3</td><td>340.00</td><td>1020</td></tr><tr class="totalprice"><td colspan="5">Grand Total Price</td><td id="grandtotal">2050</td></tr></table>
Источник таблицы непосредственно взят с веб-страницы, в точности такой же. Однако Gmail, Hotmail и большинство других писем будут игнорировать, чтобы отобразить это как таблицу.
Так что мне интересно, не используя Outlook или другое программное обеспечение для отправки электронной почты, как я могу создать встроенную таблицу для метода PHP mail() для отправки?
Текущий фрагмент кода соответствует генерации таблицы:
$purchaseinfo = $_POST["purchaseinfo"];
//if html tags are not to be filtered in the body of email
$stringBuilder .= "<table>" .stripslashes($purchaseinfo) ."</table>";
//must send json response back to caller ajax request
if(mail($email, 'Your purchase information on www.hardlyworldtravel.com', $emailbody, $headers))
echo json_encode(array("feedback"=>"successful"));
else echo json_encode(array("feedback"=>"error"));
Любые советы и предложения приветствуются, спасибо много заранее.
Отредактировано:
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//carft body of email to a human readable format
function buildEmailBody()
{
global $firstname, $lastname, $address1, $address2, $city, $state, $postcode, $country,
$cardnum, $email, $purchaseinfo;
$stringBuilder = ""; // * there is not such a thing as string builder in PHP
$stringBuilder .= "Dear " .$firstname ." " .$lastname ." :\n";
$stringBuilder .= "Thank you for purchasing flight tickets with us, here is your receipt :\n\n";
$stringBuilder .= "Your tickets will be deliverd by mail to the following address : \n";
$stringBuilder .= "Street Address 1 : " .$address1 ."\n";
$stringBuilder .= ($address2!="") ? "Street Address 2 : " .$address2 ."\n" : "Street Address 2 : N/A\n";
$stringBuilder .= "City : " .$city;
$stringBuilder .= ($state!="") ? "State : " .$state : "State : N/A ";
$stringBuilder .= "Postcode : " .$postcode ."\n";
$stringBuilder .= "Country : " .$country ."\n";
$stringBuilder .= "Credit Card Number : " .$cardnum ."\n\n";
$stringBuilder .= "Your purchase details are recorded as : \n\n";
//if html tags are not to be filtered in the body of email
$stringBuilder .= "<table>" .stripslashes($purchaseinfo) ."</table>";
//otherwise this will be painful to retrieve info out of the html table.
return $stringBuilder;
}
Можете ли вы показать, где таблица на самом деле положить в E-Mail ($ emailbody)? –
@Pekka: извините, забыли добавить код, я обновлю вопрос. –