How to email in PHP

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

Post Reply
johnsonzhang
Forum Newbie
Posts: 3
Joined: Sun Apr 06, 2003 5:33 am
Contact:

How to email in PHP

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
Post Reply