PHP/HTML Email in a script.. Help Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

PHP/HTML Email in a script.. Help Please

Post by nickman013 »

ok i got a form on my website.. when people fill it out and everything it brings them to another page which emails the form to be ... it all works good. however i wanted to know how to make a email that uses php and html in it...


this is the html/php script that needs to be emailed to me..

Code: Select all

<html>

<div align="center"><center><table WIDTH="600" BORDER="0">
        <tr>
          <td ALIGN="center" VALIGN="top" style="border: 1px"><font COLOR="#000000"><b>General
          Information</b></font></td>
        </tr>
        <tr>
          <td ALIGN="center" style="border: 1px"><table WIDTH="590" CELLPADDING="2" CELLSPACING="0"
          BORDER="0">
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Name:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$realname</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Address:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$address</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">City:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$City &nbsp; <b>State:</b> $State
              &nbsp;&nbsp; <b>ZIP:</b> $Zip</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">County:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$County &nbsp; <b>Email:</b> $email</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Residence of:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$ResidenceOf
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If township, enter name</font>$EnterTownship</td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Phone Day:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$DayPhone( &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <b>Night:</b> $NightPhone</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Date of Birth:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1"> $DateOfBirth &nbsp;&nbsp;&nbsp; Do you use tobacco in any form?&nbsp; $TobaccoUse </font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Amount of <br>
              Coverage:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1"> $AmountOfCoverage </font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Type of <br>
              Coverage<br>
              Desired?</font></b></td>
              <td ALIGN="LEFT" VALIGN="middle"><font SIZE="-1"><div align="left"><p>$TypeOfLife</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"></td>
              <td ALIGN="LEFT" VALIGN="TOP"></td>
            </tr>
          </table>
          </td>
        </tr>
      </table>
      </center></div><div align="center"><center><table WIDTH="600" BORDER="0">
        <tr>
          <td ALIGN="center" VALIGN="top"><font COLOR="#000000"><b>Additional Comments:</b></font></td>
        </tr>
        <tr>
          <td ALIGN="CENTER"><table WIDTH="590" CELLPADDING="2" CELLSPACING="0" BORDER="0">
            <tr>
              <td ALIGN="center"><table BORDER="0" CELLSPACING="0" width="585">
                <tr>
                  <td ALIGN="center" width="618"><font SIZE="-1">Please give any additional comments about
                  the coverage you desire:<br>
                  $comments</font></td>
                </tr>
              </table>
              </td>
            </tr>
          </table>
          </td>
        </tr>
      </table>
      </center></div><div align="center"><center><table BORDER="0" CELLPADDING="5">
        <tr>
         
        </tr>
      </table>
      </center></div></td>
    </tr>
  </table>
  </center></div>
</form>

<p align="center"><strong><i>Thank you for your time in submitting this life insurance
quote form. <br>
</i><em>Please allow 1 day for quotation.</em></strong><br>
</p>
</body>
</html>
the mail script is...

Code: Select all

<? 
 mail("nickman013@mac.com,nick@regionalplanning.com,angela@regionalplanning.com",
"Regional Planning Home Quote Submission Form","Submitted Content 

EMAIL STUFF HERE!

?>
<html>

<form name="redirect">
<center>
<font face="Arial"><b>You will be redirected in:<br><br>
<form>
<input type="text" size="3" name="redirect2">
</form>
seconds</b></font>
</center>

<script>
<!--



//change below target URL to your own
var targetURL="http://regionalplanning.com"
//change the second to start counting down from
var countdownfrom=5


var currentsecond=document.redirect.redirect2.value=countdownfrom+1
function countredirect(){
if (currentsecond!=1){
currentsecond-=1
document.redirect.redirect2.value=currentsecond
}
else{
window.location=targetURL
return
}
setTimeout("countredirect()",1000)
}

countredirect()
//-->
</script>
</html>
where it says EMAIL STUFF HERE i would put the php/html script in.. however it will not work.. howdo i do this?


feyd | please post php code using

Code: Select all

tags[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have the first file actually be a script that creates the html as a string. Store all that inside a function that returns this string for you to email.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

feyd, thank you for responding very fast.

i am quite a noobie at this .. can you please tell me this in noob words. thank you again
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. create a :arrow: string using the first file's HTML (the file you want to send).
  2. store this string for use by your script (I'd suggest creating a :arrow: function)
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

thanks again for the quick response...

this is probly simple to you to do...

this will probly take me 3-4 weeks lol... thanks alot

also... is there a easier tutorial or somthing than the one you provided me?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

here's a quick head start example:

Code: Select all

function generateEmail($realname, $address)
{
  return <<<STOP
<html>

<div align="center"><center><table WIDTH="600" BORDER="0">
        <tr>
          <td ALIGN="center" VALIGN="top" style="border: 1px"><font COLOR="#000000"><b>General
          Information</b></font></td>
        </tr>
        <tr>
          <td ALIGN="center" style="border: 1px"><table WIDTH="590" CELLPADDING="2" CELLSPACING="0"
          BORDER="0">
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Name:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$realname</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Address:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$address
STOP;
}

// ..........

mail("nickman013@mac.com,nick@regionalplanning.com,angela@regionalplanning.com",
"Regional Planning Home Quote Submission Form",generateEmail($realname, $address));
You'll have to add more function arguments as you add more parts of the email. The string example I used above is a heredoc, which is talked about on the string page of the manual I linked to earlier. The function page (linked to earlier) will explain what arguments are and how they are added to a function's call to pass the data into the function.

This assumes you know all the variables used inside the HTML at the time of creating the email (which you should, don't you?)
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

ok i think i did it right

Code: Select all

function generateEmail($realname, $Address, $City, $State, $Zip, $County, $email, $ResidenceOf, $EnterTownship, $DayPhone, $NightPhone, $DateOfBirth, $TobaccoUse, $AmountOfCoverage, $TypeOfLife, $comments)
{
return <<<STOP
<html>

<div align="center"><center><table WIDTH="600" BORDER="0">
        <tr>
          <td ALIGN="center" VALIGN="top" style="border: 1px"><font COLOR="#000000"><b>General
          Information</b></font></td>
        </tr>
        <tr>
          <td ALIGN="center" style="border: 1px"><table WIDTH="590" CELLPADDING="2" CELLSPACING="0"
          BORDER="0">
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Name:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$realname</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Address:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"
><font SIZE="-1">$address</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">City:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$City &nbsp; <b>State:</b> $State
              &nbsp;&nbsp; <b>ZIP:</b> $Zip</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">County:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$County &nbsp; <b>Email:</b> $email</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Residence of:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$ResidenceOf
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If township, enter name</font>$EnterTownship</td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Phone Day:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1">$DayPhone( &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <b>Night:</b> $NightPhone</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Date of Birth:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1"> $DateOfBirth &nbsp;&nbsp;&nbsp; Do you use tobacco in any form?&nbsp; $TobaccoUse </font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Amount of <br>
              Coverage:</font></b></td>
              <td ALIGN="LEFT" VALIGN="TOP"><font SIZE="-1"> $AmountOfCoverage </font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"><b><font SIZE="-1">Type of <br>
              Coverage<br>
              Desired?</font></b></td>
              <td ALIGN="LEFT" VALIGN="middle"><font SIZE="-1"><div align="left"><p>$TypeOfLife</font></td>
            </tr>
            <tr>
              <td ALIGN="right" VALIGN="bottom"></td>
              <td ALIGN="LEFT" VALIGN="TOP"></td>
            </tr>
          </table>
          </td>
        </tr>
      </table>
      </center></div><div align="center"><center><table WIDTH="600" BORDER="0">
        <tr>
          <td ALIGN="center" VALIGN="top"><font COLOR="#000000"><b>Additional Comments:</b></font></td>
        </tr>
        <tr>
          <td ALIGN="CENTER"><table WIDTH="590" CELLPADDING="2" CELLSPACING="0" BORDER="0">
            <tr>
              <td ALIGN="center"><table BORDER="0" CELLSPACING="0" width="585">
                <tr>
                  <td ALIGN="center" width="618"><font SIZE="-1">Please give any additional comments about
                  the coverage you desire:<br>
                  $comments</font></td>
                </tr>
              </table>
              </td>
            </tr>
          </table>
          </td>
        </tr>
      </table>
      </center></div><div align="center"><center><table BORDER="0" CELLPADDING="5">
        <tr>
         
        </tr>
      </table>
      </center></div></td>
    </tr>
  </table>
  </center></div>
</form>
STOP;
}

// ..........

mail("nickman013@mac.com,nick@regionalplanning.com,angela@regionalplanning.com",
"Regional Planning Home Quote Submission Form",generateEmail($realname, $Address, $City, $State, $Zip, $County, $email, $ResidenceOf, $EnterTownship, $DayPhone, $NightPhone, $DateOfBirth, $TobaccoUse, $AmountOfCoverage, $TypeOfLife, $comments);

feyd | please use

Code: Select all

tags when posting php code.[/color]
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

due to the help of feyd i got this working...

feyd helped me on MSN messenger and he didnt give up or ignore me like most other people would have.

feyd tryed to solve the problem and it didnt work the first time so he figured out what was wrong and he fixed it for me.

i wish i could have known about these forums a while ago :D

thanks again feyd
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Afterall, Feyd is the allknowing god...

what was the problem?
what was the fix?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the lowdown:
nickman013's server is running php3 ("dear lord!" you say!)
So although my initial suggestion is perfectly valid for php4 (I did not know it was php3 at that time), we had to change that around to a bigass quoted string. (Wee!)

that's the gist.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

For the love of god, upgrade.
If that's not possible in the futur mention you are using php3.. it's a whole new ball game.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

i can upgrade... its the owners web host anyway (earthlink), they got the site like 5 years ago and we can move to their new servers but it will take 2 days and at the time we didnt have time to move to the new server. but when we do i will have everythig updated
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

from personal experience.. "move away from the Earthlink, please step away from the Earthlink, sir."

I've had waking nightmares dealing with them.. not fun. I'm not going to suggest where to go, and no one else should either (or you'll face my wrath "Yes, you. I'm talking to you, the guy in the red shirt and Harry Potter style glasses. :twisted:") as a hell of a lot of hosts are talked about in :arrow: Web Hosting
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

its business hosting from earthlink if it makes a difference.
what kind of problems did you have with them?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

their support for a client's hosting account.. it was just super painful to deal with them..
Post Reply