简体   繁体   中英

Unable to send mail using PHP using Godaddy email credentials

code:

<?php
    try {
        require_once "Mail.php";
        require_once "Mail/mime.php";
        $from = "support@domain.com";
        $to = "user@gmail.com";
        $subject = "Testing email please ignore";
        $message = "Just testing";
        $host = "godaddyhost";
        $port = "465";
        $username = "support@domain.com";
        $password = "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, $message); 
        if (PEAR::isError($mail)) { 
              echo("<p>" . $mail->getMessage() . "</p>");
        } else {
                echo("<p>Message successfully sent!</p>");
        }

    } catch(Exception $e) {
        echo $e;
    }
    ?>

I'm facing an issue in the browser on executing the above script

This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500

If I comment my code from $mail = $smtp->send($to, $headers, $message); and just simply echo "something"; then I can see something on my browser

Log

[Wed Dec 27 17:07:36.033665 2017] [:error] [pid 28115] [client ::1:41546] PHP Warning:  include_once(Net/SMTP.php): failed to open stream: No such file or directory in /usr/share/php/Mail/smtp.php on line 365
[Wed Dec 27 17:07:36.033715 2017] [:error] [pid 28115] [client ::1:41546] PHP Warning:  include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/php/Mail/smtp.php on line 365
[Wed Dec 27 17:07:36.033741 2017] [:error] [pid 28115] [client ::1:41546] PHP Fatal error:  Class 'Net_SMTP' not found in /usr/share/php/Mail/smtp.php on line 366

Please install "Net/" classes.

Use this command on Linux machine, sudo pear install Net_SMTP OR

pear install Net_SMTP for windows machine. OR

downloaded the following, and put them in /Net

http://pear.php.net/package/Net_SMTP/download

http://pear.php.net/package/Net_Socket/download

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM