Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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和gmail发送电子邮件的最佳方式是什么?_Php_Email_Gmail - Fatal编程技术网

使用php和gmail发送电子邮件的最佳方式是什么?

使用php和gmail发送电子邮件的最佳方式是什么?,php,email,gmail,Php,Email,Gmail,使用php和gmail发送电子邮件的最佳方式是什么 我找到了下面的链接: 但在下载了PHPMailer的网站后,我找不到class.PHPMailer.php 你能告诉我一种发送邮件的方式吗(gmail服务器和php局域网) 另一个问题是我的gmail帐户设置为smtp/可以吗 致以最诚挚的问候我建议您与它的SmtpTransport一起使用,您可以将smtp.gmail.com指定为smtp服务器,并将其指定为使用SSL : 编辑, 根据要求-以下是一个完整的示例(未经测试): 您的免费主机

使用php和gmail发送电子邮件的最佳方式是什么

我找到了下面的链接:

但在下载了PHPMailer的网站后,我找不到class.PHPMailer.php

你能告诉我一种发送邮件的方式吗(gmail服务器和php局域网)

另一个问题是我的gmail帐户设置为smtp/可以吗

致以最诚挚的问候

我建议您与它的SmtpTransport一起使用,您可以将smtp.gmail.com指定为smtp服务器,并将其指定为使用SSL

:

编辑, 根据要求-以下是一个完整的示例(未经测试):


您的免费主机上可能包含Zend Framework

因此,您可以使用Zend Mail:

您是否可以在不使用phpmailer的情况下向我展示完整的代码以及所有功能,如ssl/port/html body…您可能想在以下位置查看类似的SO问题:您是否可以学习phpmailer或更简单的方法!/因为我想在一个免费的主机上测试它,而且它看起来很快就可以了…phpmailer站点中没有文档/为什么?我如何使用它的项目?我只想发送邮件(用gmail)/你能为我写一个完整的代码吗?这里是我读过的PHPMailer示例/但下载PHPMailer后没有class.PHPMailer.php文件!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!那是哪里
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
    ->setPort(465)
    ->setEncryption('ssl')
    ->setUsername('yourname@gmail.com')
    ->setPassword('YOUR_SECRET_PWD');
...
<?php
require_once "lib/swift_required.php";

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
    ->setPort(465)
    ->setEncryption('ssl')
    ->setUsername('yourname@gmail.com')
    ->setPassword('YOUR_SECRET_PWD');

$mailer = Swift_Mailer::newInstance($transport);

$htmlBody = '<html><body><h1>HTML-mail example!</h1><p>Contents</p></body></html>';
$plainBody = 'Looks like you cannot read HTML-emails? This is alternative content only for you.';

$message = Swift_Message::newInstance('This is the subject of the e-mail')
    ->setFrom(array('yourname@gmail.com' => 'You Name'))
    ->setTo(array('yourfriend@domain.com' => 'Your Friends Name'))
    ->setBody($plainBody)
    ->addPart($htmlBody, 'text/html');

$mailer->send($message);