2011-09-06 23 views
-2

我使用以下腳本作爲鉤子inan AppGini應用程序在提交表單時發送消息。它的功能正常,但使用純文本格式。我已經嘗試了很多次插入html格式,但每次嘗試都以失敗告終。在PHP鉤子中將文本消息修改爲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/

+1

請格式化您的問題,並提出問題 –

+1

您不是生成HTML電子郵件,而是將大量文本填入郵件正文中。爲了便於HTML +明文郵件生成,請查看[Swiftmailer](http://swiftmailer.org)和/或[PHPMailer](http://phpmailer.worxware.com)。 –

+0

有了這麼大量的電子郵件,可能會更容易創建一個'$ data'鍵和他們的英文定義數組,然後將它們映射到一個函數,該函數使用'$ data'中的值輸出英文定義。 –

回答

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"> 
     &nbsp;</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"> 
     &nbsp;</td> 
     <td width="310" align="left">&nbsp;</td> 
     <td width="216" align="left">&nbsp;</td> 
     <td width="271" align="left">&nbsp;</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">&nbsp;</td> 
     <td width="271" align="left">&nbsp;</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"> 
     &nbsp;</td> 
     <td width="310" align="left">&nbsp;</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">&nbsp;</td> 
     <td width="271" align="left">&nbsp;</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"); 

?> 
+0

感謝您提供可能的解決方案。我有一個使用Pear在生成的應用程序之外工作的函數。 –