Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Location
    India
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Send Email Function

    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.

  • #2
    Regular Coder
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Handy if you just want basic mail sent with the correct headers

    I've recently written something a bit more powerful but it would be a bit of an overkill unless you're sending several emails

  • #3
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #4
    New to the CF scene
    Join Date
    Jun 2006
    Location
    India
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    send email

    Quote Originally Posted by fci
    The email function i have contributed is easy o understand and edit. Its aim is to just send simple email.

  • #5
    Regular Coder
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by amandeep.sandhu
    The email function i have contributed is easy o understand and edit. Its aim is to just send simple email.
    Indeed Looks good.

  • #6
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    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.
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #7
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Hopefully newer users will see this and the number of posts titled "HELP WITH MAIL()" or something similar will diminish

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

  • #8
    New to the CF scene
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by d11wtq View Post
    Handy if you just want basic mail sent with the correct headers

    I've recently written something a bit more powerful 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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •