Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Mar 2007
    Posts
    45

    Arrow Send Email From PHP Using SMTP Authentication (Guide)

    Hello,
    This is useful article. In this article I am showing how to send email from PHP using SMTP Authentication for WHM/cPanel Servers.

    Everybody knows that normal php mail functions sending emails as a nobody and this is cause to spam emails.

    Login to your root SSH and copy/use following command line to your SSH line.
    Code:
    pear install Mail;pear install Net_SMTP;pear install Auth_SASL;
    After above command, you can use the following php script and send real emails. Below script is sample, you may create your own email form scripts using pear.

    ATTENTION: Following script using your dedicated IP for sending emails, do not create multiple email send scripts otherwise your server will be black listed. Use it for your user signup scripts, email verification scripts ...

    PHP Code:
    <?php
    require_once "Mail.php";
    $from "MyName <name@myemail.com>";
    $to "TargetName <name@targetemail.com>";
    $subject "Hi!";
    $body "Hi,\n\nHow are you?";
    $host "mail.mailserver.com";
    $username "name@myemail.com";
    $password "my_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>");
    }
    ?>
    Last edited by WhmSonic; 11-15-2007 at 06:19 PM.
    Best Regards,
    WHMSonic Plugins Administrator ( ShoutCast Admin Pro Plugin )
    Details Click Here

  2. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Note, if you're doing this via the cPanel interface - installing the PHP PEAR package "Mail" will install all of that for you .

    Just giving the standard head's up that using SuPHP will avoid the user nobody issue, but I understand not everyone wants to use SuPHP on their servers .

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    3

    Default

    Could you explain a little more how to install PEAR via the CPanel? I am looking at the CPanel interface and am not seeing what I can use to install the package. I've tried logging into my host using Putty to do it the first way that was suggested, but apparently this type of access has not been activated for my account.

  4. #4
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by Lawrence89 View Post
    Could you explain a little more how to install PEAR via the CPanel? I am looking at the CPanel interface and am not seeing what I can use to install the package. I've tried logging into my host using Putty to do it the first way that was suggested, but apparently this type of access has not been activated for my account.
    In the cPanel 11/X3 interface, go to the Software/Services section and click on PHP PEAR Packages. On that page, you can install PHP PEAR packages.

    If you are not using the X3 theme or not using cPanel 11, please contact your web hosting provider and encourage them to use cPanel 11 with the X3 theme as that is recommended at this time.

  5. #5
    Member
    Join Date
    Nov 2002
    Posts
    49

    Default

    Thanks very much!

    Regards,
    octeto

    Quote Originally Posted by WhmSonic View Post
    Hello,
    This is useful article. In this article I am showing how to send email from PHP using SMTP Authentication for WHM/cPanel Servers.

    Everybody knows that normal php mail functions sending emails as a nobody and this is cause to spam emails.

    Login to your root SSH and copy/use following command line to your SSH line.
    Code:
    pear install Mail;pear install Net_SMTP;pear install Auth_SASL;
    After above command, you can use the following php script and send real emails. Below script is sample, you may create your own email form scripts using pear.

    ATTENTION: Following script using your dedicated IP for sending emails, do not create multiple email send scripts otherwise your server will be black listed. Use it for your user signup scripts, email verification scripts ...

    PHP Code:
    <?php
    require_once "Mail.php";
    $from "MyName <name@myemail.com>";
    $to "TargetName <name@targetemail.com>";
    $subject "Hi!";
    $body "Hi,\n\nHow are you?";
    $host "mail.mailserver.com";
    $username "name@myemail.com";
    $password "my_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>");
    }
    ?>
    Pewkayal,
    Octeto
    Inet
    Inet-Red6-Netcafe

Similar Threads & Tags
Similar threads

  1. Enable SMTP Authentication for PHP Mail
    By wqqar in forum E-mail Discussions
    Replies: 2
    Last Post: 01-08-2011, 02:36 AM
  2. how to force sending email always use smtp authentication
    By wp11b in forum E-mail Discussions
    Replies: 3
    Last Post: 05-20-2009, 10:49 AM
  3. exim can use send email without smtp authentic
    By yanayun in forum E-mail Discussions
    Replies: 1
    Last Post: 07-17-2008, 10:31 AM
  4. ASPX Email Form send without authentication?
    By odiego in forum E-mail Discussions
    Replies: 1
    Last Post: 10-11-2007, 12:23 AM
  5. smtp - cannot send email !!!
    By jneub in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 03-26-2004, 10:59 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube