如何使用 PHP 获取批处理文件发送电子邮件?

发布于 2024-12-20 12:15:08 字数 2207 浏览 1 评论 0原文

我在 Stacked Overflow 和其他论坛上发现了许多关于使用批处理文件发送电子邮件的帖子,例如: 从 PHP 页面使用 GMail SMTP 服务器发送电子邮件

但似乎没有一个对我有用...我已经能够安排任务..使用 Windows 任务计划程序并编写批处理文件:

@回声 start C:\wamp\bin\php\php5.3.1\php.exe -f C:\wamp\www\email.php

PHP 文件显示了一个简单的脚本,如下所示:

<?php
require_once "Mail.php";

$from = "Prashant Yahoo <[email protected]>";
$to = "Prashant Hotmail <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "ssl:\\smtp.gmail.com";
$port = "465";
$username = "<[email protected]>"; or user.gmail.com as stated in the above SO link
$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, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>

我已经在本地主机上安装了 PEAR,并且我已经在本地主机上安装了 PEAR。需要。我什至下载了最新的 OpenSSL 并替换了必要的文件,并按照此处的指示设置环境变量: http://raibledesigns.com/wiki/Wiki.jsp?page=ApacheSSL

我收到以下错误:

无法连接到 ssl://smtp.gmail.com:465 [SMTP:无法连接套接字:无法找到套接字传输“ssl”- 您是否在配置 PHP 时忘记启用它? (代码:-1,响应:)]

怎么解决这个问题呢?请帮忙..

回答 在 C:\PHP 中打开 PHP.INI 文件,或者在我的例子中为 C:\WAMP\BIN\PHP\PHP 5.3.8,然后删除前面的分号: 扩展名=php_openssl.dll 和扩展名=php_sockets.dll 希望这会帮助别人! ~~~~~~特别感谢托马斯~~~~~~~

I have found numerous posts on Stacked overflow and other forums regarding sending the email using a batch file like: Send email using the GMail SMTP server from a PHP page

But none seems to work for me... I have been able to schedule task.. using Windows task scheduler and wrote the batch file:

@echo
start C:\wamp\bin\php\php5.3.1\php.exe -f C:\wamp\www\email.php

PHP file shows a simple script as below:

<?php
require_once "Mail.php";

$from = "Prashant Yahoo <[email protected]>";
$to = "Prashant Hotmail <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "ssl:\\smtp.gmail.com";
$port = "465";
$username = "<[email protected]>"; or user.gmail.com as stated in the above SO link
$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, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>

I have PEAR setup on my local host already and everything I need. I even downloaded the latest OpenSSL and replaced the necessary files and as directed here and set environment variables:
http://raibledesigns.com/wiki/Wiki.jsp?page=ApacheSSL

I receive the following error:

Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Unable to find the socket transport "ssl" -
did you forget to enable it when you configured PHP? (code: -1, response: )]

How to solve this? Please help..

ANSWER
OPEN YOUR PHP.INI FILE INSIDE THE C:\PHP or in my case C:\WAMP\BIN\PHP\PHP 5.3.8 and remove the semi-colon's ahead of:
extension=php_openssl.dll and extension=php_sockets.dll
Hope this would help someone else! ~~~~~~ Special Thanks to Tomas ~~~~~~~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哽咽笑 2024-12-27 12:15:08

回答

在 C:\PHP 中打开 PHP.INI 文件,或者在我的例子中为 C:\WAMP\BIN\PHP\PHP 5.3.8,并删除前面的分号:extension=php_openssl.dll 和 extension= php_sockets.dll 希望这对其他人有帮助!
~~~~~~特别感谢托马斯~~~~~~~

ANSWER

OPEN YOUR PHP.INI FILE INSIDE THE C:\PHP or in my case C:\WAMP\BIN\PHP\PHP 5.3.8 and remove the semi-colon's ahead of: extension=php_openssl.dll and extension=php_sockets.dll Hope this would help someone else!
~~~~~~ Special Thanks to Tomas ~~~~~~~

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文