NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP Mail function code

LeeEyerman at aol.com LeeEyerman at aol.com
Sat Jul 24 20:39:04 EDT 2004


 
I believe in order to put the from information, you need to build the  
Headers properly before sending using the mail command.
 
I.e.. Usually I will use $FromName and pass it to the $headers along with  
other stuff.  I just keep .= the $headers and send them with the mail  command. 
See below.
 
$headers="From: ".$FromName." <".$FromName.">\n"; 
mail ($email,  $subject, $message, $headers);  

I have always built complex headers for emails out of PHP for a bunch of  
reasons.  I never saw this before: 

mail($email, $subject, $body, "From: $from");  I don't think you  can just 
stick the From at the end - I am pretty sure I went down this  exact path about 
a year ago - but who can remember.
 
Good info on email headers and building them:
 
_http://www.expita.com/header1.html_ (http://www.expita.com/header1.html) 
 
 
Lee
 
 
In a message dated 7/24/2004 7:23:49 PM Eastern Daylight Time,  
hans not junk at nyphp.com writes:

The mail function  isn't in the if-else construct, so it'll get sent no 
matter what.  Are  you getting any errors?  Maybe _http://php.net/mysql_error_ 
(http://nyphp.org/mysql_error)  would help  to let you know if there's another DB 
issue at  hand. 
H 
 
 
  
____________________________________
 
From:  talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On 
Behalf Of Steven W. Riedy
Sent: Saturday, July 24, 2004 6:50  PM
To:  talk at lists.nyphp.org
Subject:  [nycphp-talk] PHP Mail function code
 
Hello,
 

 
Below is some code  that writes input from a form to a MySQL DB.  It was 
running fine until I  added the email function seen at the end.  Now this does not 
write to the  DB, but the email is getting sent.  Any ideas  why?
 

 
Thanks
 
Steve
 
(Newbie)
 

 
<?php 
$host =  'localhost'; 
$user =  'xxxxxxx'; 
$pass =  'xxxxxxx'; 
$myDB =  'candles'; 
$connect =  mysql_connect($host, $user, $pass); 
//insert string for  first table 
$today = date('M d  Y'); 
$table_name =  'logon'; 
//create query  string to insert data into table 
$query = "INSERT  INTO $table_name (today, fname, lname, address, city, 
state, zip, email,  password, passCheck, passQuestion, passAnswer) VALUES 
('$today', '$fname',  '$lname', 
'$address', '$city',  '$state', '$zip', '$email', '$password', '$passCheck', 
'$passQuestion',  '$passAnswer')"; 
?> 
(I left out all the  print statements where it was printing the info back to 
the  form) 
-------------------------- 
<?php 
//Print statement to verify if connection and inserts were  made 
mysql_select_db($myDB); 
if (mysql_query($query, $connect)){ 
print "Your logon request registration was successful on $today!  Your  
password and logon info will be emailed to you  shortly"; 
} else { 
print "Your brochure request failed to  register!"; 
} mysql_close ($connect); 
?> 
</font> 
<?php 
//Send email to registrant advising of userid and  password 
$body = "Registration complete: Password=$password Userid=$email Answer to  
Question:$passAnswer"; 
$from = 'candleman at rcn.com'; 
$subject = "Logon info for $fname $lname"; 
mail($email, $subject, $body, "From: $from"); 
?>   




 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20040724/ddd14139/attachment.html>


More information about the talk mailing list