The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Send Email From PHP Using SMTP Authentication (Guide)

Discussion in 'E-mail Discussions' started by WhmSonic, Nov 15, 2007.

  1. WhmSonic

    WhmSonic Well-Known Member

    Joined:
    Mar 19, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    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:
    <?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>");
    }
    ?>
     
    #1 WhmSonic, Nov 15, 2007
    Last edited: Nov 15, 2007
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    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. Lawrence89

    Lawrence89 Registered

    Joined:
    Jan 31, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    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. octeto

    octeto Well-Known Member

    Joined:
    Nov 9, 2002
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    Thanks very much!

    Regards,
    octeto

     
Loading...

Share This Page