email with php - VeggieBoards
Forum Jump: 
Thread Tools
#1 Old 10-08-2006, 07:25 AM
Join Date: Oct 2001
Posts: 10,763
Yea! I finally figured out how to send email using a web form, and php. It is easier than using perl. Next thing for me to do is secure the page with a javascript validator so people can't send extra messages via cc and bcc.

Oh my glob, this is your opportunity to send me an email without disclosing your email address!

However I am just parroting the key phrase. I don't really understand exactly what I am saying there, with "list($key$value)", but first we bundle up the array elements ($recip[element])from the form page into a single scalar variable which will later become the body of the msg:

while (list($key,$value) = each($recip)) {

$thebod.="$key: $value 


I couldn't figure out how to get an array such as $recip[elements] into the mail() instruction (below), so that it would work. Or even how to print out the whole array with one instruction. So I bundled the array up into a long scalar ($thebod)

Then we put the body string ($thebod) into a msg, like this

mail($to, $subject, $thebod, $theheaders )

It would be better to do that last part like this
if (mail($to, $subject, $thebod, $theheaders )) {


Yer mail were sent, baby!</p>");

 } else {


Yer mail were not sent, sorry honey.</p>");


In Perl tho, the key phrase to bundle up the variables into a mail body variable is
foreach $field (sort ($query->param)) {

    foreach $value ($query->param($field)) {

        $mail_body .= "$field: $value\


where $mail_body will be our mail body. Quite a bit longer. And whatever "$query->parm" means. And I'm not sure why the "sort" was necessary.

Then, with perl, we put the body into a msg, like this
open(MAIL, "|$sendmail -oi -t") or die "Can't open pipe to $sendmail: $!\

print MAIL "To: $sender\

print MAIL "From: $fromus\

print MAIL "Subject: Your web form submissions\

print MAIL "$mail_body";

close(MAIL) or die "Can't close pipe to $sendmail: $!\

That is also a little more time-consuming than the php way. And I can't remember what the -oi and -t mean.
soilman is offline  
Sponsored Links

Quick Reply

Register Now

In order to be able to post messages on the VeggieBoards forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Please enter a password for your user account. Note that passwords are case-sensitive.
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:


Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off