PHP mail sample code is not working

Discussion in 'Site Programming, Development and Design' started by JasonS, Dec 22, 2013.

  1. Hi,
    I am following the PHP mail sample under knowledge base (http://support.Winhost.com/KB/a826/how-to-send-email-from-a-php-application.aspx). But I am getting the following error:
    Fatal error: Class 'Mail' not found in E:\web\granatu1\testing3\mail.php on line 16

    I am using Winhost hosting plan so I think I should be able to run the script in the url above directly. Here is the script inside my mail.php file:

    <html>
    <head><title>Test email via php</title></head>
    <body>
    <?
    require_once "Mail.php";
    $from = "Sender <[email protected]>"; //using a real address in my code
    $to = "Recipient <[email protected]>"; //using a real address in my code
    $subject = "This is a test email sent via php";
    $body = "This is a test email";
    $host = "mail.my.domain"; //using my mail server under Winhost in my code
    $username = "testuser"; //using actual email user in my code
    $password = "password"; //using password of the user above
    $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);
    //here is the error
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' =>$password));
    $mail = $smtp->send($to, $headers, $body);
    ?>
    </body>
    </html>

    Since the error was raised at line 16, I believe the line (require_once "Mail.php"; ) was executed correctly.
    Can anyone tell me why I am having the error? Any help will be appreciated.

    Regards,
    Jason
     
    Last edited by a moderator: Oct 14, 2015
  2. ComputerMan

    ComputerMan Winhost Staff

    For the username field... Did you use just the name? Or did you really use [email protected] ?

    I ask because you need to use the real full email address to authenticate against the SMTP service on the mail server.
     

Share This Page