Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 谷歌邮件的SMTP脚本_Php_Wordpress_Email_Smtp_Gmail - Fatal编程技术网

Php 谷歌邮件的SMTP脚本

Php 谷歌邮件的SMTP脚本,php,wordpress,email,smtp,gmail,Php,Wordpress,Email,Smtp,Gmail,我从这里得到了下面的脚本。我的网站正在运行Digital Ocean托管,我无法发送邮件。 你能帮我工作吗。还有,我怎么知道 真正的邮件失败 #!/usr/bin/php <?php if (PHP_SAPI !== 'cli') exit; if (count($argv) < 4) { echo 'Usage: ' . basename($_SERVER['PHP_SELF']) . ' <recipient1#recipient2#...> "<sub

我从这里得到了下面的脚本。我的网站正在运行Digital Ocean托管,我无法发送邮件。 你能帮我工作吗。还有,我怎么知道 真正的邮件失败

#!/usr/bin/php
<?php

if (PHP_SAPI !== 'cli') exit;
if (count($argv) < 4) {
  echo 'Usage: ' . basename($_SERVER['PHP_SELF']) . '  <recipient1#recipient2#...> "<subject>" <"msg" or file>'."\n";
  exit;
}

require_once "Mail.php";

$from         = "xxx@gmail.com";
$aRecipients  = (strpos($argv[1], '#')) ? explode('#', $argv[1]) : array($argv[1]);
$to           = '';
foreach ($aRecipients as $recipient) $to .= "{$recipient},";
$to           = rtrim($to, ',');
$subject      = $argv[2];
$body         = '';
if (file_exists($argv[3])) {
  echo "[+] Delivering file {$argv[3]} to {$to}\n";
  $body = file_get_contents($argv[3]); 
} else {
  $length = strlen($argv[3]);
  echo "[+] Delivering text with length of {$length} to {$to}\n";
  $body = "{$argv[3]}";
}

$host     = gethostbyname('smtp.gmail.com'); 
$port     = 465; 
$username = "xxxx@gmail.com";
$password = "xxx";

$headers = array(
    'From'    => $from,
    'To'      => $to,
    'Subject' => $subject
);

$smtp =& Mail::factory('smtp',
    array(
    'host'      => $host,
    'port'      => $port,
    'debug'     => true, // set to true if u want to see what happens in the background
    'auth'      => true,
    'username'  => $username,
    'password'  => $password
    )
);

$smtp->send($to, $headers, $body);
echo "[+] Mail sent :)\n";

?>
将您的主机smtp.gmail.com更改为ssl://smtp.gmail.com

试试这个

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'XXX@gmail.com',
        'password' => 'xxx'
    ));

它可能会帮助您

尝试将smtp.gmail.com替换为ssl://smtp.gmail.comTry 阅读:谢谢,不工作。你能告诉我在哪里可以看到显示邮件已从我的邮箱中移出的日志吗?如果$smtp->send$to,$headers,$body{echo working;}或者{echo failed |},请检查if条件它不会解决问题,但有助于识别。你想让我硬编码吗?我做错什么了吗?我想说把smtp.gmail.com改成ssl://smtp.gmail.comI 没有看到结果。