Page 1 of 1

How to email in PHP

Posted: Wed Apr 16, 2003 5:21 am
by johnsonzhang
who can help me ?i'm a newbie in PHP. i'd like to know how to send an email in PHP?tell me more about it.thank you

Posted: Wed Apr 16, 2003 5:31 am
by m3mn0n
with the mail()function.

Here is an example of the proper syntax:

Code: Select all

<?php
$subject = "urgent!!";
$msg = "hello\n\n just testing";
$header = "From: "johnsonzhang" <johnsonzhang@yoursite.com>";
if(mail($to, $subject, $msg,$header)) { 
echo "Mail Sent"; 
} else { 
echo "Mail Not Sent" ; 
} 
?>


Here is how to send HTML email:

Code: Select all

<?php
$to = "johnsonzhang@yoursite.com"; 
$subject = "Test"; 
$message ='Testing
<br><br><br>
<img src=http://www.devnetwork.net/forums/templates/subSilver/images/logo_phpBB.gif>'; 

$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "From: Sam <mahamedf@telusplanet.net>\r\n"; 

if(mail($to, $subject, $message,$headers)) { 
echo "Mail Sent"; 
} else { 
echo "Mail Not Sent" ; 
} 
?>
Also, your server must have a proper smtp connection.