发邮箱php(发邮箱给别人怎么操作)

hacker|
194

怎么利用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代码:

[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") . "?=";

$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

$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 如何编写用户注册后自动发送邮件到用户邮箱?

1、进入自己已有的邮箱,设置帐户,选择“开启POP3/SMTP服务”并保存更改。我就哪我现有设置好的邮箱给大家演示(注:我用的是腾讯企业邮箱,特别注意我画红部分,第一个必要设置就是在邮箱里设置:开启POP/SMTP服务,第二个就是必要获取POP服务器的信息),如图: 2、进入dede后台,系统,系统基本参数,核心设置,配置好邮箱发信的信息.以下是我的配置(说明和如演示图):是否启用smtp方式发送邮件:是.smtp服务器:smtp.exmail.qq.com (注:因为我用的是QQ企业邮箱,所以可以参照上图演示第二个画红部分.POP服务器为:我所填写的:smtp.exmail.qq.com,一般这个POP服务器的填写不是乱填,请一定要参考你使用的邮箱他们所在的POP服务器.)smtp服务器端口:25 (一般这个不需要可以去修改改变.默认为:25)SMTP服务器的用户邮箱:webmaster@asqq8.net (这里填写完整的邮箱地址)SMTP服务器的用户帐号:webmaster (这里填写邮箱开头的账户也就是用户名)SMTP服务器的用户密码:123456 (密码就不用多说了)3.进入dede后台,系统,系统基本参数,会员设置,在“会员使用权限开通状态(-10邮件验证-1手工审核,0没限制)”填-10 如图:教程演示操纵到这里,已经可以收到邮件了

如何用php结合phpmailer发送邮件

?php 

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

ini_set("magic_quotes_runtime",0); 

require 'php_mail/class.phpmailer.php'; 

require 'php_mail/class.smtp.php'; 

function send_mail($to,$fromname,$title,$content){ 

try { 

$mail = new PHPMailer(true); 

$mail-IsSMTP(); 

$mail-CharSet='UTF-8'; //设置邮件的字符编码,这很重要,不然中文乱码 

$mail-SMTPAuth = true; //开启认证 

$mail-Port = 25; //端口请保持默认

$mail-Host = "smtp.163.com"; //使用QQ邮箱发送

$mail-Username = "xxxxxxxxxx@163.com"; //这个可以替换成自己的邮箱

$mail-Password = "xxxxxxxxxxxxxxx"; //注意 这里是写smtp的授权码 写的不是QQ密码,此授权码不可用

//$mail-IsSendmail(); //如果没有sendmail组件就注释掉,否则出现“Could not execute: /var/qmail/bin/sendmail ”的错误提示 

$mail-AddReplyTo("xxxxxxxxx@163.com","mckee");//回复地址 

$mail-From = "xxxxxxxxxxx@163.com"; 

$mail-FromName = $fromname; 

$to = $to; 

$mail-AddAddress($to); 

$mail-Subject = $title; 

$mail-Body = $content;

$mail-AltBody = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示,可以省略 

$mail-WordWrap = 80; // 设置每行字符串的长度 

//$mail-AddAttachment("f:/test.png"); //可以添加附件 

$mail-IsHTML(true); 

$mail-Send(); 

// echo '邮件已发送';

} catch (phpmailerException $e) { 

// echo "邮件发送失败:".$e-errorMessage(); 

return true;

}

$neirong="联系电话:".$_POST['phone']."br /".$_POST['content']."hrp style='float:right;'邮件来自官网/p";

send_mail('654080169@qq.com',$_POST['fromname'],'来信了ヾ(≧O≦)〃嗷~',$neirong);

// send_mail('1486064793@qq.com',$_POST['fromname'],'可爱的保氧家官网来信了ヾ(≧O≦)〃嗷~',$neirong);

//环境 PHP5.3亲测可用

?

下载邮件类,结合这个就可以了

PHP怎么使用阿里云企业邮箱发邮件?

找个PHPMailer类

$mail = new \Vendor\PHPMailer(); //PHPMailer对象

$mail-CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码

$mail-IsSMTP(); // 设定使用SMTP服务

$mail-SMTPDebug = 0; // 关闭SMTP调试功能

$mail-SMTPAuth = true; // 启用 SMTP 验证功能

$mail-SMTPSecure = 'ssl'; // 使用安全协议

$mail-Host = $config['SMTP_HOST']; // SMTP 服务器

$mail-Port = $config['SMTP_PORT']; // SMTP服务器的端口号

$mail-Username = $config['SMTP_USER']; // SMTP服务器用户名

$mail-Password = $config['SMTP_PASS']; // SMTP服务器密码

$mail-SetFrom($config['FROM_EMAIL'], $config['FROM_NAME']);

$replyEmail = $config['REPLY_EMAIL'] ? $config['REPLY_EMAIL'] : $config['FROM_EMAIL'];

$replyName = $config['REPLY_NAME'] ? $config['REPLY_NAME'] : $config['FROM_NAME'];

$mail-AddReplyTo($replyEmail, $replyName);

$mail-Subject = $subject;

$mail-MsgHTML($body);

$mail-AddAddress($to, $name);

if (is_array($attachment)) {

// 添加附件

foreach ($attachment as $file) {

is_file($file) $mail-AddAttachment($file);

}

}

return $mail-Send() ? true : $mail-ErrorInfo;

5条大神的评论

  • avatar
    访客 2022-09-20 下午 02:20:47

    配置好邮箱发信的信息.以下是我的配置(说明和如演示图):是否启用smtp方式发送邮件:是.smtp服务器:smtp.exmail.qq.com (注:因为我用的是QQ企业邮箱,所以可以参照上图演示第二个画红部分

  • avatar
    访客 2022-09-20 上午 07:07:27

    :因为我用的是QQ企业邮箱,所以可以参照上图演示第二个画红部分.POP服务器为:我所填写的:smtp.exmail.qq.com,一般这个POP服务器的填写不是乱填,请一定要参考你使用的邮箱他们所在的P

  • avatar
    访客 2022-09-20 上午 06:41:20

    ue="1"/ 邮箱地址: input type="text" size="50" name="to" / br/ input type="submit" value="发送"/ /form /body

  • avatar
    访客 2022-09-20 上午 05:05:53

    xample script using PHPMailer with exceptions enabled * @package phpmailer * @version $Id$ */ he

  • avatar
    访客 2022-09-20 上午 07:20:25

    "magic_quotes_runtime",0); require 'php_mail/class.phpmailer.php'; require 'php_mail/class.s

发表评论