当前位置:首页 » 编程语言 » php发送qq邮件

php发送qq邮件

发布时间: 2023-04-27 19:36:04

A. 本地php能发邮件吗

可以的

比较简单的是颤旦借用外部SMTP服务器发送邮箱,比如现在的QQ邮箱是支持SMTP服务的,然后利用phpmailer,作些简单毕没设置茄数扰即可

B. 如何在phpcms中设置smtp验证发送邮件

一、使用易网库提供的企业邮箱

1.登录phpcms后台,点击“设置”——“邮箱配置”进入邮箱设置界面,如图1

C. PHP中的SMTP servers该怎么解决 我的SMTP servers设置为smtp.qq.com。是不是只能给QQ邮箱发送

smtp.qq.com
可以向所有邮箱发送,QQ邮箱只是作为你的邮件发送服务器

D. php利用mail发送邮件问题

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

试一下这个

$conf['mail'] = array(
'host' => 'mail.abc.net', //smtp服务器地腔乎址,可以用ip地址或者域名
'auth' => true, //true表示smtp服务器需要验证,false代码不需要
'username' => '[email protected]', //用户名
'password' => '*****' //密码
);

<?php
require_once 'Mail.php';

$conf['mail'] = array(
'host' => 'mail.abc.net', //smtp服务器地址,可以用ip地址或者域名
'auth' => true, //true表示smtp服务器需要验证,false代码不需要
'username' => '[email protected]', //用户名
'password' => '******' //密码
);

/***
* 使用$headers数组,可以定义邮件头的内容,比如使用$headers['Reply-To']可以定义回复地址
* 通过这种方式,可以很方便的定制待发送邮件的邮件头
***/
$headers['From'] = '[email protected]'; //发信地址
$headers['To'] = '[email protected]'; //收信地址
$headers['Subject'] = 'test mail send by php'; //邮件标题
$mail_object = &Mail::factory('smtp', $conf['mail']);

$body = "<h1>meg</h1>"; //邮件正文

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

if( Mail::isError($mail_res) ){ //检测错误
die($mail_res->getMessage());
}
echo "ok";
?>

E. 我想用PHP写个表单直接发送到 QQ邮箱,最好网站不登陆也能发的。最好能写出具体的代码

<?
/*
* 邮件发送类
*/
class smail {
//您的SMTP 服务器供应商,可以是域名或IP地址
var $smtp = "";
//SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系。
var $check = 1;
//您的email帐号名称
var $username = "";
//您的email密码
var $password = "";
//此email 必需是销银发信服务器上的email
var $s_from = "";

/*
* 功能:发信初始化设置渣大
* $from 你的发信服务器上的邮箱
* $password 你的邮箱密码
* $smtp 您的SMTP 服务器供应商,可以是域名或IP地址
* $check SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证
*/
function smail ( $from, $password, $smtp, $check = 1 ) {
if( preg_match("/^[^\d\-_][\w\-]*[^\-_]@[^\-][a-zA-Z\d\-]+[^\-](\.[^\-][a-zA-Z\d\-]*[^\-])*\.[a-zA-Z]{2,3}/如斗竖", $from ) ) {
$this->username = substr( $from, 0, strpos( $from , "@" ) );
$this->password = $password;
$this->smtp = $smtp ? $smtp : $this->smtp;
$this->check = $check;
$this->s_from = $from;
}
}

/*
* 功能:发送邮件
* $to 目标邮箱
* $from 来源邮箱
* $subject 邮件标题
* $message 邮件内容
*/
function send ( $to, $from, $subject, $message ) {

//连接服务器
$fp = fsockopen ( $this->smtp, 25, $errno, $errstr, 60);
if (!$fp ) return "联接服务器失败".__LINE__;
set_socket_blocking($fp, true );

$lastmessage=fgets($fp,512);
if ( substr($lastmessage,0,3) != 220 ) return "错误信息1:$lastmessage".__LINE__;

//HELO
$yourname = "YOURNAME";
if($this->check == "1") $lastact="EHLO ".$yourname."\r\n";
else $lastact="HELO ".$yourname."\r\n";

fputs($fp, $lastact);
$lastmessage == fgets($fp,512);
if (substr($lastmessage,0,3) != 220 ) return "错误信息2:$lastmessage".__LINE__;
while (true) {
$lastmessage = fgets($fp,512);
if ( (substr($lastmessage,3,1) != "-") or (empty($lastmessage)) )
break;
}

//身份验证
if ($this->check=="1") {
//验证开始
$lastact="AUTH LOGIN"."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息3:$lastmessage".__LINE__;
//用户姓名
$lastact=base64_encode($this->username)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息4:$lastmessage".__LINE__;
//用户密码
$lastact=base64_encode($this->password)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != "235") return "错误信息5:$lastmessage".__LINE__;
}

//FROM:
$lastact="MAIL FROM: <". $this->s_from . ">\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息6:$lastmessage".__LINE__;

//TO:
$lastact="RCPT TO: <". $to ."> \r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息7:$lastmessage".__LINE__;

//DATA
$lastact="DATA\r\n";
fputs($fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 354) return "错误信息8:$lastmessage".__LINE__;

//处理Subject头
$head="Subject: $subject\r\n";
$message = $head."\r\n".$message;

//处理From头
$head="From: $from\r\n";
$message = $head.$message;

//处理To头
$head="To: $to\r\n";
$message = $head.$message;

//加上结束串
$message .= "\r\n.\r\n";

//发送信息
fputs($fp, $message);
$lastact="QUIT\r\n";

fputs($fp,$lastace);
fclose($fp);
return 0;
}
}
/*发送示例
$sm = new smail( "用户名@163.com", "密码", "smtp.163.com" );
$end = $sm->send( "目标邮箱", "来源邮箱", "这是标题", "这是邮件内容" );
if( $end ) echo $end;
else echo "发送成功!";
*/
?>

F. 如何用PHP里的IMAP函数,实现邮件的发送,希

//以腾讯企业邮箱做了测试
$mailServer="imap.exmail.qq.com";//IMAP主机
$mailLink="{{$mailServer}:143}INBOX";//imagp连接地址:不同主机地址不同
$mailUser='***';//邮箱用户名
$mailPass='***';//邮箱密码
$mbox=imap_open($mailLink,$mailUser,$mailPass);//开启信箱imap_open
$totalrows=imap_num_msg($mbox);//取得信件数
for($i=1;$i<$totalrows;$i++){
$headers=imap_fetchheader($mbox,$i);//获取信件标头
$headArr=matchMailHead($headers);//匹配信件标头
$mailBody=imap_fetchbody($mbox,$i,1);//获取信件正文
}
/**
*
*匹配提取信件头部信息
*@paramString$str
*/
functionmatchMailHead($str){
$headList=array();
$headArr=array(
'from',
'to',
'date',
'subject'
);
foreach($headArras$key){
if(preg_match('/'.$key.':(.*?)[ ]/is',$str,$m)){
$match=trim($m[1]);
$headList[$key]=$key=='date'?date('Y-m-dH:i:s',strtotime($match)):$match;
}
}
return$headList;
}

G. PHP中发送邮件的代码!

从代码来看,想必楼主是想把表单提交的内容发送至指定邮箱,而这个邮箱地址也是在表单中填写的,$sendTo变量的值被赋为表单项“toMail”传过来的值。
如此,你可以在填写表单的时候在toMail表单项里填入“[email protected]”,或者直接$sendTo="[email protected]"。

接下来就要考虑是否能发送出去了:

1、如果楼主配置的服务器安装了sendmail组件,就可以直接使用你写的这段代码来完成任务。

2、如果没有安装sendmail组件,就要接用smtp服务器来发送了。这样相对较复杂,要引用一个PHP类。具体代码如下:

SMTP.PHP:
<?php
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;

/* Private Variables */
var $sock;

/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()

#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;

#
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";

$this->sock = FALSE;
}

/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header = "MIME-Version:1.0\r\n";

if($mailtype=="HTML")
{
$header .= "Content-Type:text/html\r\n";
}

$header .= "To: ".$to."\r\n";

if ($cc != "")
{
$header .= "Cc: ".$cc."\r\n";
}

$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";

list($msec, $sec) = explode(" ", microtime());

$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";

$TO = explode(",", $this->strip_comment($to));

if ($cc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}

if ($bcc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}

$sent = TRUE;

foreach ($TO as $rcpt_to)
{
$rcpt_to = $this->get_address($rcpt_to);

if (!$this->smtp_sockopen($rcpt_to))
{
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}

if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body))
{
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else
{
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}

fclose($this->sock);

$this->log_write("Disconnected from remote host\n");
}

return $sent;
}

/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo))
{

return $this->smtp_error("sending HELO command");
}

#auth
if($this->auth)
{
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user)))
{
return $this->smtp_error("sending HELO command");
}

if (!$this->smtp_putcmd("", base64_encode($this->pass)))
{
return $this->smtp_error("sending HELO command");
}
}

#
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">"))
{
return $this->smtp_error("sending MAIL FROM command");
}

if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">"))
{
return $this->smtp_error("sending RCPT TO command");
}

if (!$this->smtp_putcmd("DATA"))
{
return $this->smtp_error("sending DATA command");
}

if (!$this->smtp_message($header, $body))
{
return $this->smtp_error("sending message");
}

if (!$this->smtp_eom())
{
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}

if (!$this->smtp_putcmd("QUIT"))
{
return $this->smtp_error("sending QUIT command");
}

return TRUE;
}

function smtp_sockopen($address)
{
if ($this->relay_host == "")
{
return $this->smtp_sockopen_mx($address);
}
else
{
return $this->smtp_sockopen_relay();
}
}

function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}

$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;
}

function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS))
{
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}

foreach ($MXHOSTS as $host)
{
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}

$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}

$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}

function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}

function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}

function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");

if (!ereg("^[23]", $response))
{
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}

function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "")
{
if($cmd=="")
$cmd = $arg;
else
$cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}

function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}

function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "")
{
return TRUE;
}

$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a")))
{
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;
}

flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}

function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address))
{
$address = ereg_replace($comment, "", $address);
}
return $address;
}

function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}

function smtp_debug($message)
{
if ($this->debug)
{
echo $message;
}
}
}
?>

DEMO:TEST.PHP
<?php
require "smtp.php";
$smtpserver = "smtp.xxx.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "[email protected]";//SMTP服务器的用户邮箱
$smtpemailto = "[email protected]";//发送给谁
$smtpuser = "xxxx";//SMTP服务器的用户帐号
$smtppass = "xxxx";//SMTP服务器的用户密码
$mailsubject = "客户反馈意见!";//邮件主题
$mailbody = "<h1>这是我的一个测试~~~</h1>";//邮件内容
$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件

$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->debug = false;//是否显示发送的调试信息
$return = ($smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype));
echo $return;
?>

H. 怎么用php的mail函数发邮件

functionsendMail($to,$title,$content){

Vendor('PHPMailer.PHPMailerAutoload');
$mail=newPHPMailer();//实例化
$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版本的。

I. php如何发送邮件

php发送邮件,php发送电子邮件,使用php发送邮件,php如何发送邮件
方法/步骤
1
在实际项目开发中,我们经常需要得到用户的反馈信息并及时回复。普通的留言板有一定的内容限制,而悉春邮件则能满足这个需求。今天给大家演示一下怎么利用PHP发送电子邮件。
2
1.首先我们需要一个用来发送电子邮件的文件的程序,也就是一个php文件,流行的phpmail有很多,今天以smtp.php为例来演示。


3
2.将其复制到你的项目文件内,具体路径根据自己的实际情况,这里建了一个test文件,用来设置邮件参数,大家也可以自定义邮件参数文件。(PS:一般都是通过表单接受的)

4
3.smtp.php文件如图所示,大家不需要管代码,会用就行,有时间了也可以研究研究哈。

5
4.设置邮亏陆凳件参数,具体代码如下:
//引入发送邮件类
require("smtp.php");

//使用163邮箱服务器
$smtpserver="smtp.163.com";

//163邮箱服务器端口
$smtpserverport=25;

//你的163服务器邮箱账号
$smtpusermail="@163.com";

//收件人邮箱
$smtpemailto="@qq.com";

//你的邮箱账号(去掉@163.com)
$smtpuser="";//SMTP服务器的用户帐号

//你的邮箱密码
$smtppass="";//SMTP服务器的用户密码

6
5.设置邮件内容,代码如下:
//邮件主题
$mailsubject="测试邮件发送";

//邮件内容
$mailbody="PHP+MySQL";

//邮件格式(HTML/TXT),TXT为文本邮件
$mailtype="TXT";

//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp=newsmtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);

//是否显示发送的调试信息
$smtp->debug销旅=TRUE;

//发送邮件
$smtp->sendmail($smtpemailto,$smtpusermail,$mailsubject,$mailbody,$mailtype);
刷新页面后邮件发送,参数不出错的话1分钟左右即可发送成功。我在测试的时候没有发送成功提示,自己登录邮箱查看的,如图所示,内容和上面设置的一样。

J. 如何用php结合phpmailer发送邮件

步骤图解教程demo和

phpmailer代码包下载:

看这个博主的文章,新手也能实现php发送邮件:网页链接

热点内容
这个锁屏密码是什么 发布:2024-11-01 12:24:51 浏览:91
相机存储卡排名 发布:2024-11-01 12:24:49 浏览:957
androidxml格式化 发布:2024-11-01 12:23:14 浏览:164
Vb6编译是错误不知道错误代码 发布:2024-11-01 12:16:23 浏览:158
局域网电脑访问服务器怎么提速 发布:2024-11-01 12:14:09 浏览:321
美创数据库 发布:2024-11-01 12:05:45 浏览:915
你改爱奇艺密码什么意思 发布:2024-11-01 12:04:48 浏览:408
矩阵分解python 发布:2024-11-01 11:58:23 浏览:366
如何查询微信支付密码修改记录 发布:2024-11-01 11:51:57 浏览:206
如何运维gpu服务器 发布:2024-11-01 11:45:23 浏览:366