×

phpmail函?蛋l送?]件

phpmail函?蛋l送?]件(php邮件)

admin admin 发表于2023-03-20 23:04:10 浏览54 评论0

抢沙发发表评论

本文目录一览:

如何使用php的mail函数发送邮件

可以用官方内置的phpmail进行发送也可以找对应的函数类做。

希望我的回答可以帮到你,有什么不懂可以追问。

怎么用php的mail函数发邮件

function sendMail($to, $title, $content) {

    Vendor('PHPMailer.PHPMailerAutoload');

    $mail = new PHPMailer(); //实例化

    $mail-IsSMTP(); // 启用SMTP

    $mail-Host=C('MAIL_HOST'); //smtp服务器的名称(这里以QQ邮箱为例)

    $mail-SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证

    $mail-Username = C('MAIL_USERNAME'); //你的邮箱名

    $mail-Password = C('MAIL_PASSWORD') ; //邮箱密码

    $mail-From = C('MAIL_FROM'); //发件人地址(也就是你的邮箱地址)

    $mail-FromName = C('MAIL_FROMNAME'); //发件人姓名

    $mail-AddAddress($to,"尊敬的客户");

    $mail-WordWrap = 50; //设置每行字符长度

    $mail-IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件

    $mail-CharSet=C('MAIL_CHARSET'); //设置邮件编码

    $mail-Subject =$title; //邮件主题

    $mail-Body = $content; //邮件内容

    $mail-AltBody = ""; //邮件正文不支持HTML的备用显示

    $relt = $mail-Send();

    if(!$relt) {

        writeLog('发送邮件错误,错误信息:'. $mail-ErrorInfo, 1, '发送邮箱失败');

    }

    return($relt);

}

这个是thinkphp版本的。

php利用mail发送邮件问题

那你可以参考一下PW的程序.

试一下这个

$conf['mail'] = array(

'host' = 'mail.abc.net', //smtp服务器地址,可以用ip地址或者域名

'auth' = true, //true表示smtp服务器需要验证,false代码不需要

'username' = 'abc@abc.net', //用户名

'password' = '*****' //密码

);

?php

require_once 'Mail.php';

$conf['mail'] = array(

'host' = 'mail.abc.net', //smtp服务器地址,可以用ip地址或者域名

'auth' = true, //true表示smtp服务器需要验证,false代码不需要

'username' = 'abc@abc.net', //用户名

'password' = '******' //密码

);

/***

* 使用$headers数组,可以定义邮件头的内容,比如使用$headers['Reply-To']可以定义回复地址

* 通过这种方式,可以很方便的定制待发送邮件的邮件头

***/

$headers['From'] = 'abc@abc.net'; //发信地址

$headers['To'] = 'abc@abc.com'; //收信地址

$headers['Subject'] = 'test mail send by php'; //邮件标题

$mail_object = Mail::factory('smtp', $conf['mail']);

$body = "h1meg/h1"; //邮件正文

$mail_res = $mail_object-send($headers['To'], $headers, $body); //发送

if( Mail::isError($mail_res) ){ //检测错误

die($mail_res-getMessage());

}

echo "ok";

?

PHP如何使用MAIL函数发邮件

PHP mail 发送邮件

mail

(PHP 4, PHP 5)

mail — 发送邮件

说明

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )-phpmail函?蛋l送?]件

发送一封电子邮件。

参数

to

电子邮件收件人,或收件人列表。

本字符串的格式必须符合 » RFC 2822。例如:

user@example.com

user@example.com, anotheruser@example.com

User user@example.com

User user@example.com, Another User anotheruser@example.com

subject

电子邮件的主题。

Caution

本项不能包含任何换行符,否则邮件可能无法正确发送。

message

所要发送的消息。

行之间必须以一个 LF( )分隔。每行不能超过 70 个字符。

Caution

(Windows 下)当 PHP 直接连接到 SMTP 服务器时,如果在一行开头发现一个句号,则会被删掉。要避免此问题,将单个句号替换成两个句号。 ?php

$text = str_replace(" .", " ..", $text);

?

additional_headers(可选项)

String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF ( ).-phpmail函?蛋l送?]件

怎么利用php发送邮件求详细教程

PHP虽然提供了mail()函数,但并不好用,而PHPMailer是一个不错的邮件发送工具,接下来将详细介绍,需要了解的朋友可以参考下:

本人使用wamp集成开发环境,Apache2.4.4, Mysql5.6.12 , php5.4.12.开始的时候使用mail()发送邮件,更改配置始终无法成功,了解到mail()函数使用需要sendmail程序。又下载了sendmail程序扩展包。按照网上的说法也改好了php.ini和sendmail.ini。使用foxmail 7.1创建了自己的qq邮箱账户,开启了POP3/SMTP服务,更改发件服务器为POP3,使用和收件服务器相同的身份验证,结果还是报错:Warning: mail(): SMTP server response: 503 Error: need EHLO and AUTH first ! in F:\PHP\wamp\www\mail.php on line 8。以下是使用mail()函数发送邮件的php代码:-phpmail函?蛋l送?]件

[php] view plain copy

span style="font-size:14px"?php

$to = "757006080@qq.com";

$subject = "Test mail";

$message = "Hello! This is a simple email message.";

$from = "757006080@qq.com";

$headers = "From: $from";

$send=mail($to,$subject,$message,$headers);

if($send)

echo "Mail Sent";

else

echo "Sorry,mail sent failed!"

?/span

在CSDN论坛上发现phpmailer可以方便快捷的发送邮件,以下写出详细使用教程:

1.需要下载PHPMailer文件包,(点击打开链接)

2.确认你的服务器已经系统支持socket,通过phpinfo()查看是否支持socket;

3.把文件解压到你的WEB服务器目录下,就可以使用PHPMailer发送邮件了。

以下为前台表单php代码:

[php] view plain copy

span style="font-size:14px"html

body

h3phpmailer Unit Test/h3

请你输入font color="#FF6666"收信/font的邮箱地址:

form name="phpmailer" action="testemail.php" method="post"

input type="hidden" name="submitted" value="1"/

邮箱地址: input type="text" size="50" name="to" /

br/

input type="submit" value="发送"/

/form

/body

/html /span

以下为后台程序:

[php] view plain copy

?php

/**

* Simple example script using PHPMailer with exceptions enabled

* @package phpmailer

* @version $Id$

*/

header("content-type:text/html;charset=utf-8");

ini_set("magic_quotes_runtime",0);

require('class.phpmailer.php');

try {

$mail = new PHPMailer(true); //New instance, with exceptions enabled

//$body = file_get_contents('contents.html');

//$body = preg_replace('/\\\\/','', $body); //Strip backslashes

$to = $_POST['to'];

$mail-CharSet="GB2312";//设置邮件字符编码否则邮件会乱码

$mail-Encoding="base64";

$mail-IsSMTP(); // tell the class to use SMTP

$mail-SMTPAuth = true; // enable SMTP authentication

$mail-Port = 25; // set the SMTP server port

$mail-Host = "smtp.qq.com"; // SMTP server

$mail-Username = "757006080@qq.com"; // SMTP server username

$mail-Password = "000000000000"; // SMTP server password

//$mail-IsSendmail(); // tell the class to use Sendmail

$mail-AddReplyTo("757006080@qq.com","han qing");

$mail-From = "757006080@qq.com";

$mail-FromName = "han qing";

//$to = "hanqing757@gmail.com";

$mail-AddAddress($to);

$mail-Subject =$mail-Subject = "=?utf-8?B?" . base64_encode("First PHPMailer Message") . "?="; -phpmail函?蛋l送?]件

$mail-Body = "h1phpmailer演示/h1 这是用PHPMAILER发的第一份邮件,从QQ邮箱发到Google邮箱.";

$mail-AddAttachment("F:/myloe.jpg");

$mail-AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test -phpmail函?蛋l送?]件

$mail-WordWrap = 80; // set word wrap

//$mail-MsgHTML($body);

$mail-IsHTML(true); // send as HTML

$mail-Send();

echo 'Message has been sent.';

} catch (phpmailerException $e) {

echo $e-errorMessage();

}

?

如何在php用mail发送邮件

有两种方法

一、使用PHP内置的mail()函数

二、使用封装SMTP协议的邮件类

具体可以参考这篇文章,希望对你有帮助