Jump to content

PHP to eMail [Resolved]


nate51

Recommended Posts

I'm new to this forum and semi new to php. I am in need of help badly here as I have a deadline going.

 

I have a registry page (html) with fields for name, number, address etc.

 

The way I used to do php reg forms was to have a first page with fill in boxes (fields) after filling in clicking submit would link to a second page thanking people for registering...

 

An email would go to a specified email address displaying the information entered into the fields. Really basic script really simple but affective.

 

I now need to make an html email so that the field information is sent to a specific email address with html code around it to present the information to look more like a fill out card with a logo on the top right, then the basic simple text style.

 

I have been looking for awhile and am coming up dry for answers. Most of the tutorials I find don't detail how to make the field information display in the html email.

 

Can anyone help me? Or point me in the right direction?

 

-- Nathan

Link to comment
Share on other sites

He wants to send them a HTML formatted email

Bingo!

 

The way I know of and am used to is someone goes to a page fills out the form hits send and they see a "Thank you" page. Now someone on another end recieves an email with all their information to do what they please with it, i.e. enter into a data base, add to a mailing list etc.

 

But I need to change the way it arrives to the recipient. I need to change it from plain text to html.

Link to comment
Share on other sites

Go here:

http://us.php.net/manual/en/function.mail.php

 

scroll down to Example #4

 

Note: The headers are the most important

I tried this one earlier and it did help me a bit, I now get html code to my email but lines like this...

<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Full Name:</td>

<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$firstname \n</td>

<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$midname \n</td>

<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$lastname \n</td>

 

I know this is wrong because instead of getting the persons information it comes just as you see it "$firstname" etc.

 

I need to know how to make that call up the information entered into the fields.

Link to comment
Share on other sites

Ok,

 

The email now comes to my email address looking the way I want except for 2 issues remaining.

 

1. The logo I need on the right hand side is not showing even though I have allowed that email address to accept images and it is an absolute link.

2. The fields are still coming to my email like this $lastname \n. I have tried adding "" to them i.e. "$lastname \n" also like this "$lastname" and both ways don't bring the data in right.

 

btw thanks to all the replies from everyone so far.

Link to comment
Share on other sites

<?php
// multiple recipients
$to  = 'xxxx@xxxx.com';

// subject
$subject = 'e-Card';

// message
$message = '
<html>
<body bgcolor="#ffffff">

<div align=center><table border=0 cellspacing=0 cellpadding=1
bgcolor=#555555><tr><td><table border=0 cellspacing=0 cellpadding=5><tr><td
class=title colspan=5 valign=middle nowrap bgcolor=#ffffff>
<blockquote>Enrollment Card for xxxxxx</blockquote>
</td><td align=right valign=middle nowrap bgcolor=#ffffff>
<img src="http://www.xxxxxx.com/xxx/images/mail_logo.jpg" alt="[Logo]"
border=0></td>
</tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Full Name:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>"$firstname"</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>"$midname"</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>"$lastname"</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Date of Birth:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>"$dob"</td>
</tr><tr>
<td class=label align=left valign=middle nowrap bgcolor=white> </td>
<td class=footer align=left valign=middle nowrap bgcolor=white>Last</td>
<td class=footer align=left valign=middle nowrap bgcolor=white>Middle</td>
<td class=footer align=left valign=middle nowrap bgcolor=white>First</td>
<td class=content align=left valign=middle nowrap bgcolor=white> </td>
<td class=content align=left valign=middle nowrap bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Address:</td>
<td class=content colspan=3 align=left valign=middle nowrap bgcolor=#eeeeee>"$address"</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>City:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>"$city"</td>
</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Province:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>"$province"</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Postal Code:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>"$postalcode"</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Kit Requested: </td>
<td colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee class=content>"$choice"</td>
</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Telephone:</td>
<td class=content colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee>"$phone"</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Mobile Phone: </td>
<td colspan=2 align=left valign=middle bgcolor=#eeeeee class=content>"$cell"</td>

</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Beneficiary:</td>
<td class=content colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee>"$beneficiary"</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Relationship:</td>
<td class=content colspan=2 align=left valign=middle bgcolor=#eeeeee>"$relation"</td>
<tr>
<td class=label colspan=6 align=right valign=middle nowrap bgcolor=#eeeeee>SGC3O</td>
</tr></table></td></tr></table>
</body>
</html>';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?> 

 

This php is in the Thank You page.

Link to comment
Share on other sites

Double quote the string that the variable is in.

 

In regards to the logo, can't help you there, but it may be better as an attachment.

 

$message = "
<html>
<body bgcolor='#ffffff'>

<div align=center><table border=0 cellspacing=0 cellpadding=1
bgcolor=#555555><tr><td><table border=0 cellspacing=0 cellpadding=5><tr><td
class=title colspan=5 valign=middle nowrap bgcolor=#ffffff>
<blockquote>Enrollment Card for xxxxxx</blockquote>
</td><td align=right valign=middle nowrap bgcolor=#ffffff>
<img src='http://www.xxxxxx.com/xxx/images/mail_logo.jpg' alt='[Logo]'
border=0></td>
</tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Full Name:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$firstname</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$midname</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$lastname</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Date of Birth:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$dob</td>
</tr><tr>
<td class=label align=left valign=middle nowrap bgcolor=white> </td>
<td class=footer align=left valign=middle nowrap bgcolor=white>Last</td>
<td class=footer align=left valign=middle nowrap bgcolor=white>Middle</td>
<td class=footer align=left valign=middle nowrap bgcolor=white>First</td>
<td class=content align=left valign=middle nowrap bgcolor=white> </td>
<td class=content align=left valign=middle nowrap bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Address:</td>
<td class=content colspan=3 align=left valign=middle nowrap bgcolor=#eeeeee>$address</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>City:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$city</td>
</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Province:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$province</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Postal Code:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$postalcode</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Kit Requested: </td>
<td colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee class=content>$choice</td>
</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Telephone:</td>
<td class=content colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee>$phone</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Mobile Phone: </td>
<td colspan=2 align=left valign=middle bgcolor=#eeeeee class=content>$cell</td>

</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Beneficiary:</td>
<td class=content colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee>$beneficiary</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Relationship:</td>
<td class=content colspan=2 align=left valign=middle bgcolor=#eeeeee>$relation</td>
<tr>
<td class=label colspan=6 align=right valign=middle nowrap bgcolor=#eeeeee>SGC3O</td>
</tr></table></td></tr></table>
</body>
</html>";

Link to comment
Share on other sites

Double quotes didn't change anything.

 

I don't know if this helps or not but the php code I gave is in a php page that has html code to display images and text for the Thank You page.

 

Full page code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
<!--
body {
background-image: url(images/bg.jpg);
background-position:Center;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.textbox {
BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #333333 1px solid; FONT-SIZE: 11px; BACKGROUND-IMAGE: url(images/field_bg.gif); BORDER-LEFT: #333333 1px solid; COLOR: #2e415f; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; HEIGHT: 17px; BACKGROUND-COLOR: #f0eddc
}
.style9 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
.style10 {
font-size: 16px
}
.style11 {font-size: 18px}
.style12 {font-family: Arial, Helvetica, sans-serif}
.style13 {	color: #0168B3;
font-weight: bold;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onload="MM_preloadImages('images/nav/intro_btno.jpg','images/nav/group_btno.jpg','images/nav/reply_btno.jpg')">
<?php
// multiple recipients
$to  = 'xxxx@xxxx.com';

// subject
$subject = 'e_Card';

// message
$message = "
<html>
<body bgcolor="#ffffff">

<div align=center><table border=0 cellspacing=0 cellpadding=1
bgcolor=#555555><tr><td><table border=0 cellspacing=0 cellpadding=5><tr><td
class=title colspan=5 valign=middle nowrap bgcolor=#ffffff>
<blockquote>Enrollment Card for OACCPP</blockquote>
</td><td align=right valign=middle nowrap bgcolor=#ffffff>
<img src="http://www.xxxxxx.com/xxx/images/mail_logo.jpg" alt="[Logo]"
border=0></td>
</tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Full Name:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$firstname</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$midname</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$lastname</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Date of Birth:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$dob</td>
</tr><tr>
<td class=label align=left valign=middle nowrap bgcolor=white> </td>
<td class=footer align=left valign=middle nowrap bgcolor=white>Last</td>
<td class=footer align=left valign=middle nowrap bgcolor=white>Middle</td>
<td class=footer align=left valign=middle nowrap bgcolor=white>First</td>
<td class=content align=left valign=middle nowrap bgcolor=white> </td>
<td class=content align=left valign=middle nowrap bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Address:</td>
<td class=content colspan=3 align=left valign=middle nowrap bgcolor=#eeeeee>$address</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>City:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$city</td>
</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Province:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$province</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Postal Code:</td>
<td class=content align=left valign=middle nowrap bgcolor=#eeeeee>$postalcode</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Kis Kit Requested: </td>
<td colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee class=content>$choice</td>
</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Telephone:</td>
<td class=content colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee>$phone</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Mobile Phone: </td>
<td colspan=2 align=left valign=middle bgcolor=#eeeeee class=content>$cell</td>

</tr><tr>
<td class=label colspan=6 align=left valign=middle nowrap
bgcolor=white> </td></tr><tr>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Beneficiary:</td>
<td class=content colspan=2 align=left valign=middle nowrap bgcolor=#eeeeee>$beneficiary</td>
<td class=label align=right valign=middle nowrap bgcolor=#eeeeee>Relationship:</td>
<td class=content colspan=2 align=left valign=middle bgcolor=#eeeeee>$relation</td>
<tr>
<td class=label colspan=6 align=right valign=middle nowrap bgcolor=#eeeeee>SGC3O</td>
</tr></table></td></tr></table>
</body>
</html>";

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?> 

<table width="752" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="724"> </td>
  </tr>
  <tr>
    <td><div align="center"><img src="images/iaomaaw_logo.jpg" width="700" height="113" /></div></td>
  </tr>
  <tr>
    <td> </td>
  </tr>
  <tr>
    <td bgcolor="#D9D9D9"><table width="75" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('intro','','images/nav/intro_btno.jpg',1)"><img src="images/nav/intro_btn.jpg" name="intro" width="129" height="24" border="0" id="intro" /></a></td>
        <td><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('group','','images/nav/group_btno.jpg',1)"><img src="images/nav/group_btn.jpg" name="group" width="140" height="24" border="0" id="group" /></a></td>
        <td><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('reply','','images/nav/reply_btno.jpg',1)"><img src="images/nav/reply_btn.jpg" name="reply" width="131" height="24" border="0" id="reply" /></a></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="308" border="0" cellpadding="0" cellspacing="4">
      <tr>
        <td width="14" class="style9 style10"> </td>
        <td width="282" height="30" class="style9 style10"><span class="style13">Replay Card</span><br /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="357" border="0" align="center" cellpadding="0" cellspacing="8">
      <tr>
        <td width="341" class="style11 style12">Thank you for registering for a Kit</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td> </td>
  </tr>
  <tr>
    <td height="50" bgcolor="#E2E2E2"><p align="center" class="style9">Contents Copyright © xxxxxxxx. All rights reserved.<br />
    For   more information, please contact us at <a href="mailto:xxx@xxxxxx.com">xxx@xxxxxx.com</a>.</p></td>
  </tr>
</table>
</body>

</html>

Link to comment
Share on other sites

Edit: nevermind, didn't read the entire posted source.  :-\

 

Edit2: try..

<td class=content colspan=2 align=left valign=middle bgcolor=#eeeeee>' . $relation . '</td>

 

That did it!

 

Thank you so much for the help!

 

Everything works perfect.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.