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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts

    send mail() from PHP page with external SMTP host

    I use XAMPP on Windows Xp. I had to try a few different scripts till I found a working one.

    This script does not use set_ini() so no need to make any changes to php.ini , or any other XAMPP whatever page:


    PHP Code:
    <?php 

    include("Mail.php");  // Mail.php is integrated in php and not a separate file 

    $recipients "receiver@domain.com";

    $headers["From"]    = "me@sender.com";
    $headers["To"]      = "receiver@domain.com";
    $headers["Subject"] = "Test message";

    $body "TEST MESSAGE!!!";

    $params["host"] = "smtp.yourISP.com";
    $params["port"] = "25";
    $params["auth"] = true;
    $params["username"] = "YourLogin@yourISP.com";
    $params["password"] = "YourPassword";

    // Create the mail object using the Mail::factory method
    $mail_object =& Mail::factory("smtp"$params);

    $mail_object->send($recipients$headers$body); 

    ?>
    Mail.php is an internal php function, no need to have that file in the directory.

    Source: http://www.php.net/manual/en/function.mail.php#39305
    Last edited by fail; 11-28-2010 at 06:29 AM.

  • #2
    Regular Coder
    Join Date
    Dec 2007
    Posts
    137
    Thanks
    1
    Thanked 21 Times in 21 Posts
    Was there a question here?

    Or was this suppose to go in the PHP snippets sub-forum? If so, thanks for posting the code.

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Good script but also have the same question as pigpen was their a question here?

    closets Seattle
    custom closet organizers
    seattle closet organizers

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,338
    Thanks
    13
    Thanked 348 Times in 344 Posts
    Quote Originally Posted by fail View Post
    Mail.php is an internal php function, no need to have that file in the directory.

    Source: http://www.php.net/manual/en/function.mail.php#39305
    correction: Mail.php is not an internal function (built-in), it is a PEAR package.

    PS. this snippet was done by Roberto Silva
    Last edited by Dormilich; 11-29-2010 at 07:00 AM.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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