如何使用godaddy凭据从php发送电子邮件

时间:2017-12-27 17:27:57

标签: php

我使用以下代码发送电子邮件

<?php
try {
    require_once "Mail.php";
    require_once "Mail/mime.php";
    $from = "user@domain.com";
    $to = "user@gmail.com";
    $subject = "Testing";
    $message = "Hi";
    $host = "godaddyhost";
    $port = 465;
    $username = "user@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;
}
?>

我在日志文件中遇到以下错误

[Wed Dec 27 22:46:25.893118 2017] [:error] [pid 3047] [client 127.0.0.1:35984] PHP Warning:  require_once(Mail.php): failed to open stream: No such file or directory in /var/www/html/testmail.php on line 3
[Wed Dec 27 22:46:25.893195 2017] [:error] [pid 3047] [client 127.0.0.1:35984] PHP Fatal error:  require_once(): Failed opening required 'Mail.php' (include_path='.:/usr/share/php') in /var/www/html/testmail.php on line 3

我正在使用PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )PEAR Version: 1.10.5

我是否错过了安装任何套餐?

发送电子邮件的其他选择?我必须让它在本地和godaddy网站上工作。

0 个答案:

没有答案