【问题标题】:how to send mail using server-side language? [closed]如何使用服务器端语言发送邮件? [关闭]
【发布时间】:2014-06-25 12:11:03
【问题描述】:

我知道 HTML 和 CSS。我正在建立一个网站。添加了“联系我们”页面。我现在正在使用运行 linux 服务器的免费网络托管。 php邮件功能现在工作正常..

在接收用户信息时,通过网站自动发送电子邮件的其他方式有哪些?

提前谢谢..

【问题讨论】:

  • 在ini文件中配置smtp
  • 我无法访问我免费托管网站的 Web 服务器上的 php.ini 文件..

标签: php web-services email


【解决方案1】:

我建议使用 PHPMailer ,相比 php 函数 mail() 提供了更多的功能

PHPMailer - PHP 的全功能电子邮件创建和传输类

类特征

  • 可能是世界上最流行的从 PHP 发送电子邮件的代码!
  • 被许多开源项目使用:Drupal、SugarCRM、Yii、Joomla!还有更多
  • 集成 SMTP 支持 - 无需本地邮件服务器即可发送
  • 发送包含多个 TO、CC、BCC 和 REPLY-TO 的电子邮件
  • 不阅读 HTML 电子邮件的邮件客户端的多部分/替代电子邮件
  • 支持 UTF-8 内容和 8 位、base64、二进制和带引号的可打印编码
  • 通过 SSL 和 TLS 传输使用 LOGIN、PLAIN、NTLM 和 CRAM-MD5 机制进行 SMTP 身份验证
  • 本地语言支持
  • DKIM 和 S/MIME 签名支持
  • 与 PHP 5.0 及更高版本兼容
  • 还有更多!

例子

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

PHPMailer

Documentation

【讨论】:

    【解决方案2】:

    您可以尝试PHPMailer library 通过您自己的 SMTP 帐户发送电子邮件。

    示例代码:

    <?php
    require 'PHPMailerAutoload.php';
    
    $mail = new PHPMailer;
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'user@example.com';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
    
    $mail->From = 'from@example.com';
    $mail->FromName = 'Mailer';
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');
    
    $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    $mail->isHTML(true);                                  // Set email format to HTML
    
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
    

    【讨论】:

      【解决方案3】:

      您提供的有关服务器托管环境的信息很少,但正确的答案是让 php 邮件正常工作。原因有很多,没有更多信息是不可能回答的

      【讨论】:

        猜你喜欢
        • 2013-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-12
        • 2011-06-12
        • 2019-06-20
        相关资源
        最近更新 更多