我无法使用PHPMailer发送电子邮件。我在OSX(优胜美地)上运行MAMP(localhost:8888)。我按照[this] [1]教程为MAMP的php版本全局设置了composer。
nano ~/.bash_profile
alias phpmamp='/Applications/MAMP/bin/php/php5.4.34/bin/php'
curl -sS https://getcomposer.org/installer | phpmamp
sudo mv composer.phar /usr/local/bin/composer
composer
然后我在 / Applications / MAMP / htdocs
中创建了 phpmailer 目录Composer.json:
{
"require": {
"phpmailer/phpmailer": "dev-master"
}
}
然后在phpmailer目录中输入命令composer install。它下载了文件,我在phpmailer目录中创建了一个文件index.php。
从git获取依赖项后,文件结构如下所示:
phpmailer
|
|----composer.json
|----vendor(directory with various subdirectories and files)
|----index.php
|----composer.lock
调试日志:
2015-09-12 19:03:47 Connection: opening to ssl://localhost:25, timeout=300, options=array ( ) 2015-09-12 19:03:47 SMTP ERROR: Failed to connect to server: Connection refused (61) 2015-09-12 19:03:47 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting bool(false)
<?php
require_once 'vendor/autoload.php';
代码:
<?php
require_once 'vendor/autoload.php';
$m = new PHPMailer;
$m->SMTPDebug = 3;
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->SMTPDebug = 2;
$m->HOST = 'smtp.gmail.com';
$m->Username = 'myemail@gmail.com';
$m->Password = 'hidden';
$m->SMTPSecure = 'ssl';
$m->PORT = 465;
$m->From = "myemail@gmail.com";
$m->FromName = "Android Plus Ios";
$m->addReplyTo('friend@gmail.com','Reply address');
$m->addAddress('friend@mdurohtak.ac.in','Rakesh');
$m->addCC('Jettu@hotmail.com', 'Jitesh');
$m->addBCC('Fudu@outlook.com', 'Fruity');
$m->Subject = "Please verify the account.";
$m->Body = 'Please click here to verify the account registration';
$m->AltBody = 'By Google';
var_dump($m->send());
?>
答案 0 :(得分:1)
PHP是case sensitive。因此,您应该更改以下两个调用:
$m->HOST = 'smtp.gmail.com';
$m->PORT = 465;
到
$m->Host = 'smtp.gmail.com';
$m->Port = 465;