PDA

View Full Version : Send Email Function



amandeep.sandhu
06-01-2006, 12:32 PM
function sendMail($to, $name, $subject, $from, $message)
{

$headers ="MIME-Version:1.0\r\n";
$headers .="content-type:text/html; Charset=iso-8859-1\r\n";
$headers .= "From: " . "$name" . "<" . "$from" . ">\n";
$headers .= "Return-Path: <" . "$to" . ">\n";
$headers .= "Error-To: <" . "$to" . ">\n";
$headers .= "X-Sender: <" . "$to" . ">\n";
$headers .= "X-Mailer: PHP v".phpversion()."\n";


$subject= nl2br($subject);
$message=nl2br($message);
$to=$to;
$mail= mail($to, $subject, $message, $headers) ;
return $mail;
}

// How To Use

$to="amandeep.sandhu@yahoo.com";
$from="karan@yahoo.com";
$name="karan";
$subject="hello";
$message="How r u";

sendMail($to, $name, $subject, $from, $message);

You can Place function sendMail in a separate file like functions.php and then include functions.php in your current file and call function sendMail in other file. With this if you have to send email in multiple forms you have to call sendMail($to, $name, $subject, $from, $message); only.

You can Pass $to, $from , $name, $subject, $message to this function and send email to anybody.

Thanks.

d11wtq
06-01-2006, 02:24 PM
Handy if you just want basic mail sent with the correct headers :)

I've recently written something a bit more powerful (http://www.swiftmailer.org/) but it would be a bit of an overkill unless you're sending several emails ;)

fci
06-01-2006, 02:28 PM
and another:
http://pear.php.net/package/Mail/redirected

amandeep.sandhu
06-03-2006, 09:20 PM
and another:
http://pear.php.net/package/Mail/redirected

The email function i have contributed is easy o understand and edit. Its aim is to just send simple email.

d11wtq
06-03-2006, 09:37 PM
The email function i have contributed is easy o understand and edit. Its aim is to just send simple email.

Indeed :) Looks good.

ahallicks
12-06-2007, 04:43 PM
THanks for that. I've used a modified version of this that allows me to E-Mail all of the members of my site. Cheers, was very simple to use.

fl00d
12-06-2007, 11:06 PM
Hopefully newer users will see this and the number of posts titled "HELP WITH MAIL()" or something similar will diminish :D

Perhaps you can add in a notification whether the email was sent or not. Still keeps things simple :)

jhbalaji
05-12-2010, 06:52 PM
Handy if you just want basic mail sent with the correct headers :)

I've recently written something a bit more powerful (http://www.swiftmailer.org/) but it would be a bit of an overkill unless you're sending several emails ;)

Your Swift mailer package is too good!
I started to use that now :)