开发者

adapt text message to html in php hook

I use the following script as a hook inan AppGini application to send a message when a form is submitted.It functions correctly but is in plain text. I've tried many times to insert html formatting but each attempt has ended in failure.

@mail(
    "{$data['client_suiting_location']}@nonprofit.org",
    "Client Referral开发者_C百科",
    "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"
    );

The style of message I would like to send is here: http://www.grovesonline.com/mail/


Really you should use a pre-built mailing class for this, some have been suggested above.

However, if you insist on just using mail(), you need to send the message in multipart/alternative format, which you can do by using the code below. Note that this uses the exact template you liked to above, which is a little messy and the HTML could do with streamlining...

I am also assuming your $referral_email variable contains valid headers, which I doubt it does. I suspect it should probably be added to the specified like the when you send it to mail(): "From: $referral_email" but I can't be 100% sure from your question.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜