我使用以下脚本作为AppGini应用程序中的一个钩子,在提交表单时发送消息。它运行正常,但是是纯文本。我已多次尝试插入html格式,但每次尝试都以失败告终。
@mail(
"{$data['client_suiting_location']}@nonprofit.org",
"Client Referral",
"Referral_contact: {$data['referral_contact']}
Referral Partner: $referral_partner
Referral Contact Email: $referral_email
Date: {$data['creation_date']}
Client name: {$data['client_name']}
Client telephone: {$data['client_telephone']}
Client alternate telephone: {$data['client_alternate_telephone']}
Client suiting location: {$data['client_suiting_location']}
Client Interview Dates: {$data['client_interview_details']}
Client Spanish only: {$data['client_spanish']}
Client Career Center: {$data['client_career_center']}
Client Coaching Requests: {$data['client_career_requests']}
Client Interview Details: {$data['client_interview']}
Client clothes sizes: {$data['client_clothes_sizes']}
Client requests: {$data['client_requests']}
Client preferences: {$data['client_preferences']}
Client email: {$data['client_email']}
client address1: {$data['client_address1']}
Client address2: {$data['client_address2']}
Client city: {$data['client_city']}
Client state: {$data['client_state']}
Client zip: {$data['client_zip']}
Client age: {$data['client_age']}
Client height: {$data['client_height']}
Client weight: {$data['client_weight']}
Client_ethnicity: {$data['client_ethnicity']}
Client_educ_level: {$data['client_educ_level']}
Client_dependents: {$data['client_dependents']}
Client_marital_status: {$data['client_marital_status']}
Client_public_assistance: {$data['client_public_assistance']}
Client_employment_status: {$data['client_employment_status']}",
"$referral_email"
);
我想发送的邮件样式是:http://www.grovesonline.com/mail/
答案 0 :(得分:3)
你真的应该使用一个预先构建的邮件类,上面已经提出了一些。
但是,如果您坚持使用mail()
,则需要以multipart/alternative
格式发送消息,您可以使用以下代码执行此操作。请注意,这使用了您喜欢的上面的确切模板,这有点混乱,HTML可以用简化...
我还假设你的$referral_email
变量包含有效的标题,我怀疑它是否存在。我怀疑应该将它添加到指定的内容,例如当您将其发送到mail()
时"From: $referral_email"
,但我无法100%确定您的问题。
<?php
$bodytext = <<<EOD
Referral_contact: {$data['referral_contact']}
Referral Partner: $referral_partner
Referral Contact Email: $referral_email
Date: {$data['creation_date']}
Client name: {$data['client_name']}
Client telephone: {$data['client_telephone']}
Client alternate telephone: {$data['client_alternate_telephone']}
Client suiting location: {$data['client_suiting_location']}
Client Interview Dates: {$data['client_interview_details']}
Client Spanish only: {$data['client_spanish']}
Client Career Center: {$data['client_career_center']}
Client Coaching Requests: {$data['client_career_requests']}
Client Interview Details: {$data['client_interview']}
Client clothes sizes: {$data['client_clothes_sizes']}
Client requests: {$data['client_requests']}
Client preferences: {$data['client_preferences']}
Client email: {$data['client_email']}
client address1: {$data['client_address1']}
Client address2: {$data['client_address2']}
Client city: {$data['client_city']}
Client state: {$data['client_state']}
Client zip: {$data['client_zip']}
Client age: {$data['client_age']}
Client height: {$data['client_height']}
Client weight: {$data['client_weight']}
Client_ethnicity: {$data['client_ethnicity']}
Client_educ_level: {$data['client_educ_level']}
Client_dependents: {$data['client_dependents']}
Client_marital_status: {$data['client_marital_status']}
Client_public_assistance: {$data['client_public_assistance']}
Client_employment_status: {$data['client_employment_status']}
EOD;
$bodyhtml = <<<EOD
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Email Template</title>
</head>
<body>
<table border="0" width="1024">
<tr>
<td colspan="4" height="100">
<p align="center">
</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Date</font></span></td>
<td width="310" align="left">{$data['creation_date']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Referral Partner</font></span></td>
<td width="310" align="left">$referral_partner</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Referral Contact</font></span></td>
<td width="310" align="left">{$data['referral_contact']}</td>
<td width="216">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Referral Contact Email</font></span></td>
<td width="271" align="left">$referral_email</td>
</tr>
<tr>
<td width="197">
</td>
<td width="310" align="left"> </td>
<td width="216" align="left"> </td>
<td width="271" align="left"> </td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Client Name</font></span></td>
<td width="310" align="left">{$data['client_name']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Telephone</font></span></td>
<td width="310" align="left">{$data['client_telephone']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Spanish</font></span></td>
<td width="310" align="left">{$data['client_spanish']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Alternate telephone</font></span></td>
<td width="310" align="left">{$data['client_alternate_telephone']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Suiting Location</font></span></td>
<td width="310" align="left">{$data['client_suiting_location']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Career Center Visit</font></span></td>
<td width="310" align="left">{$data['client_career_center']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Interview Details</font></span></td>
<td width="310" align="left">{$data['client_interview_details']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Coaching Requests</font></span></td>
<td width="310" align="left">{$data['client_career_requests']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Clothes Sizes</font></span></td>
<td width="310" align="left">{$data['client_clothes_sizes']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Preferences</font></span></td>
<td width="310" align="left">{$data['client_preferences']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Client Email</font></span></td>
<td width="310" align="left">{$data['client_email']}</td>
<td width="216" align="left"> </td>
<td width="271" align="left"> </td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Client Address</font></span></td>
<td width="310" align="left">{$data['client_address1']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Address 2</font></span></td>
<td width="310" align="left">{$data['client_address2']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">City</font></span></td>
<td width="310" align="left">{$data['client_city']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">State</font></span></td>
<td width="310" align="left">{$data['client_state']}</td>
</tr>
<tr>
<td width="197">
</td>
<td width="310" align="left"> </td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Zip</font></span></td>
<td width="310" align="left">{$data['client_zip']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Age</font></span></td>
<td width="310" align="left">{$data['client_age']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Height</font></span></td>
<td width="310" align="left">{$data['client_height']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Weight</font></span></td>
<td width="310" align="left">{$data['client_weight']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Ethnicity</font></span></td>
<td width="310" align="left">{$data['client_ethnicity']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Education Level</font></span></td>
<td width="310" align="left">{$data['client_educ_level']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Dependents</font></span></td>
<td width="310" align="left">{$data['client_dependents']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Marital Status</font></span></td>
<td width="310" align="left">{$data['client_marital_status']}</td>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Public Assistance</font></span></td>
<td width="310" align="left">{$data['client_public_assistance']}</td>
</tr>
<tr>
<td width="197">
<span style="orphans: 2; text-align: -webkit-auto; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-weight: 700">
<font size="2" face="Verdana">Employed</font></span></td>
<td width="310" align="left">{$data['client_employment_status']}</td>
<td width="216" align="left"> </td>
<td width="271" align="left"> </td>
</tr>
</table>
</body>
</html>
EOD;
$boundary = '------'.md5(time()).'------';
$body = "This is a multipart message in MIME format\r\n$boundary\r\nContent-Type: text/plain\r\n\r\n$bodytext\r\n$boundary\r\nContent-Type: text/html\r\nContent-Transfer-Encoding: base64\r\n\r\n".base64_encode($bodyhtml)."\r\n$boundary--";
@mail("{$data['client_suiting_location']}@nonprofit.org","Client Referral",$body,"Content-Type: multipart/alternative; boundary=\"$boundary\"\r\n$referral_email");
?>