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 Script

Discussion in 'E-mail Discussions' started by Taha Kirmani, Jan 15, 2015.

  1. Taha Kirmani

    Taha Kirmani Registered

    Joined:
    Jan 15, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Karachi, Pakistan, Pakistan
    cPanel Access Level:
    Website Owner
    Hello

    I am trying to send Email from mochahost server. Their technical representative gave me following link to send mail from mochahost.

    /http://www.mochasupport.com/kayako/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=555

    I have written the following code, but its neither generating any email, nor giving any error message.

    Kindly check the following code and guide me what i am doing wrong here.

    Please also guide me that from where to get Mail.php file

    PHP:

    <?php

    //require_once "Mail.php";
    require "Mail.php";



    $from "Taha <username@Hotmail.com>";


    $to "Taha <username@Hotmail.com>";

    $subject "Hi!";

    $body "Hi,\n\nHow are you?";



    $host "111.11.11.127";

    $username "username@Hotmail.com";

    $password "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>");

     }

    ?>



     
  2. triantech

    triantech Well-Known Member

    Joined:
    Jul 1, 2014
    Messages:
    145
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Kochi, India, India
    cPanel Access Level:
    Root Administrator
    Hey,

    >> Make sure the PEAR Mail package is installed

    Did you get a change to verify this ^ ?
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    I suggest consulting with your web hosting provider for assistance with your script if you do not have root access to your server. You won't be able to review Exim logs with just cPanel access.

    Thank you.
     
  4. Taha Kirmani

    Taha Kirmani Registered

    Joined:
    Jan 15, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Karachi, Pakistan, Pakistan
    cPanel Access Level:
    Website Owner
    Thanks everyone for the reply... I have successfully installed the PEAR Mail Package. It has installed it in home/username/Php/Mail ...Now i am unable to understand that how to link this folder from my code... When i am using the following code its giving me the error message that its unable to find out the "Mail.php" file.


    PHP:
    //require "../../php/Mail.php";

    //include 'home/username/php/Mail.php';

    The both code written above is unable to find out the Mail.php file. Kindly guide me how to include "Mail.php" file.
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You may find more feedback on a forum dedicated to discussions of PHP programming or from your web hosting provider who can review the script and verify if it should work on their server.

    Thank you.
     
Loading...

Share This Page