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发送电子邮件_Php_Email_Pear - Fatal编程技术网

用PHP发送电子邮件

用PHP发送电子邮件,php,email,pear,Php,Email,Pear,我正在尝试使用PHP发送电子邮件。我在这里找到了很多帖子,我感到很失落。我试着使用许多代码,但都不起作用 最后,我阅读了关于PEAR的文章,我有以下代码,我正在使用MacOSX10.7.3和带有PHP5.3.6的MAMP 我需要做什么才能让代码正常工作,它会显示一个错误加载页面!?有任何配置吗 如果有人有一个配置说明的工作示例,请与我们分享 <?php require_once "Mail.php"; $recipients = 'receiver@live.com'; $header

我正在尝试使用PHP发送电子邮件。我在这里找到了很多帖子,我感到很失落。我试着使用许多代码,但都不起作用

最后,我阅读了关于PEAR的文章,我有以下代码,我正在使用MacOSX10.7.3和带有PHP5.3.6的MAMP

我需要做什么才能让代码正常工作,它会显示一个错误加载页面!?有任何配置吗

如果有人有一个配置说明的工作示例,请与我们分享

<?php
require_once "Mail.php";

$recipients = 'receiver@live.com';

$headers['From']    = 'sender@gmail.com';
$headers['To']      = 'receiver@live.com';
$headers['Subject'] = 'Test message';

$body = 'Test message';

$params['sendmail_path'] = '/usr/lib/sendmail';

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);

$mail_object->send($recipients, $headers, $body);

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

使用PHP发送电子邮件再简单不过了:

mail('to@email.com', 'Subject', 'Here comes the message');
就这样。请记住,您的服务器需要配置为发送电子邮件


使用PHP发送电子邮件再简单不过了:

mail('to@email.com', 'Subject', 'Here comes the message');
就这样。请记住,您的服务器需要配置为发送电子邮件


我需要什么配置以及在哪里???老实说,我从来没有这样做过(我租用的每台服务器都是正确配置的),但是阅读这篇文章时,你似乎只需要在php.ini中设置
sendmail\u path
变量来指向你的sendmail函数。与您现在在代码中所做的完全相同(将其设置为/usr/lib/sendmail)(尽管文章建议使用/usr/bin/sendmail或/usr/sbin/sendmail)。我需要什么配置以及在哪里???老实说,我从来没有这样做过(我租用的每台服务器都已正确配置),但是阅读它,您似乎只需要在php.ini中设置
sendmail\u path
变量以指向您的sendmail函数。与您现在在代码中所做的完全相同(将其设置为/usr/lib/sendmail)(尽管文章建议使用/usr/bin/sendmail或/usr/sbin/sendmail)。