Nigeria Business Forum
News: $100 for the top poster by Sept. 26th 2008!. see more >> http://business-nigeria.com/forum/index.php/topic,431.0.html
*
Welcome, Guest. Please login or register. September 10, 2010, 10:41:51 AM


Login with username, password and session length


Earn $1 for each person you bring to NBF!!!

Join now and start inviting people.Click here for more.

Pages: [1]   Go Down
Print
Author Topic: How to Send Email from a PHP Script Using SMTP Authentication  (Read 145 times)
0 Members and 31 Guests are viewing this topic.
DrSmile
Administrator
NBF SUPPORTER
*****

Reputation: +100/-1
Online Online

Gender: Male
Posts: 966


You can only be happy by making others happy


View Profile WWW
« on: August 21, 2008, 09:11:02 AM »

My programmar bolted, so when my host disabled sending mails from "nobody", I was stranded. My scripts couldn't send mails again. It took me days of research and trials to get the right code to send mails from PHP with SMTP Authentication. it's easy, just make changes and replace the dumb mail code with the one I'll paste below in red!.

Send Email from a PHP Script Using SMTP Authentication

To connect to an outgoing SMTP server from a PHP script using SMTP authentication and send an email:


    * Make sure the PEAR Mail package is installed.
          o Typically, in particular with PHP 4 or later, this will have already been done for you. Just give it a try.
    * Adapt the example below for your needs. Make sure you change the following variables at least:
          o from: the email address from which you want the message to be sent.
          o to: the recipient's email address and name.
          o host: your outgoing SMTP server name.
          o username: the SMTP user name (typically the same as the user name used to retrieve mail).
          o password: the password for SMTP authentication.

Sending Mail from PHP Using SMTP Authentication - Example

    <?php
    require_once "Mail.php";

    $from = "Sandra Sender <sender@example.com>";
    $to = "Ramona Recipient <recipient@example.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";

    $host = "mail.example.com";
    $username = "smtp_username";
    $password = "smtp_password";

    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }
    ?>


Sending Mail from PHP Using SMTP Authentication and SSL Encryption - Example

    <?php
    require_once "Mail.php";

    $from = "Sandra Sender <sender@example.com>";
    $to = "Ramona Recipient <recipient@example.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";

    $host = "ssl://mail.example.com";
    $port = "465";
    $username = "smtp_username";
    $password = "smtp_password";

    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }
    ?>
Report to moderator   Logged

Let's build this together, invite others!
Ztyle
NBF HERO
*****

Reputation: +3/-7
Online Online

Gender: Male
Posts: 1248



View Profile
« Reply #1 on: August 22, 2008, 02:47:16 AM »

Good Tips, but i don't work base on PHP, i use HTML.
Report to moderator   Logged

E-CASH BLOG => www.invest4h.blogspot.com - MAKE MONEY <=
DrSmile
Administrator
NBF SUPPORTER
*****

Reputation: +100/-1
Online Online

Gender: Male
Posts: 966


You can only be happy by making others happy


View Profile WWW
« Reply #2 on: August 22, 2008, 01:18:39 PM »

Good Tips, but i don't work base on PHP, i use HTML.

Grin u are still an amateur. Well, most of us started with html and still use it, with time, u'll upgrade!
Report to moderator   Logged

Let's build this together, invite others!
Ztyle
NBF HERO
*****

Reputation: +3/-7
Online Online

Gender: Male
Posts: 1248



View Profile
« Reply #3 on: August 22, 2008, 03:04:26 PM »

Drsmile everything is base on time, i use HTML but yet i'm not amateur u can testify of that base on my works. well i will upgrade to PHP pretty soon.
Report to moderator   Logged

E-CASH BLOG => www.invest4h.blogspot.com - MAKE MONEY <=
DrSmile
Administrator
NBF SUPPORTER
*****

Reputation: +100/-1
Online Online

Gender: Male
Posts: 966


You can only be happy by making others happy


View Profile WWW
« Reply #4 on: August 22, 2008, 08:51:22 PM »

Drsmile everything is base on time, i use HTML but yet i'm not amateur u can testify of that base on my works. well i will upgrade to PHP pretty soon.
sure, am impressed by ur progress. I started like that, with 5u.com. Check my first site www.sunej.5u.com
Report to moderator   Logged

Let's build this together, invite others!
Ztyle
NBF HERO
*****

Reputation: +3/-7
Online Online

Gender: Male
Posts: 1248



View Profile
« Reply #5 on: August 22, 2008, 09:23:46 PM »

Dude don't look down on me, mind you no body knows tomorrow.
Report to moderator   Logged

E-CASH BLOG => www.invest4h.blogspot.com - MAKE MONEY <=
DrSmile
Administrator
NBF SUPPORTER
*****

Reputation: +100/-1
Online Online

Gender: Male
Posts: 966


You can only be happy by making others happy


View Profile WWW
« Reply #6 on: August 23, 2008, 09:06:38 AM »

Dude don't look down on me, mind you no body knows tomorrow.
Did I give any impression am looking down on u?
Report to moderator   Logged

Let's build this together, invite others!
hayznet
NBF SUPPORTER
****

Reputation: +3/-0
Online Online

Posts: 476



View Profile
« Reply #7 on: September 14, 2008, 06:55:22 AM »

I dnt see u mention that too, free the Guy, he is just too 4ward.
Report to moderator   Logged
Nigeria Business Forum
   

 Logged
Pages: [1]   Go Up
Print
Jump to:  

ad costs $50/month ad costs $50/month ad costs $50/month ad costs $50/month
Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC

Proudly Nigerian
Valid XHTML 1.0! Valid CSS! . NBF