热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

邮箱接口怎么做php(邮箱登录接口)

导读:今天编程笔记来给各位分享关于邮箱接口怎么做php的相关内容,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览:1、新手想做一个PHP的表单提交发送到指定邮箱,请高手指教

导读:今天编程笔记来给各位分享关于邮箱接口怎么做php的相关内容,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:


  • 1、新手想做一个PHP的表单提交发送到指定邮箱,请高手指教?


  • 2、PHP使用邮箱发送邮件(phpmailer/phpmailer)


  • 3、请问这个发送邮箱PHP代码要怎么写

新手想做一个PHP的表单提交发送到指定邮箱,请高手指教?

首先包含一个邮件发送类 require("sendMail.php");

然后你要有一个发送邮件的服务器(可以到163随意注册个,例如注册的是aa@163.com,密码是aa123),然后是发送邮件的代码,我给你一个我用的例子

$smtpserver = "smtp.163.com"; //你选择的SMTP服务器

$smtpserverport =25; //SMTP服务器端口

$smtpusermail = "aa@163.com"; //SMTP服务器的用户邮箱

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

$smtpuser = "aa@163.com"; //SMTP服务器的用户帐号

$smtppass = "aa123"; //SMTP服务器的用户密码

$MailBody="姓名:".$_POST['Name'];//邮件内容(如你提交的表单姓名为Name)

$mailsubject=@iconv("UTF-8", "gb2312", "XX网站-问题提交");//如果你页面为UTF-8,这里还要转码一下

$mailbody = $MailBody; //邮件内容

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

$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//true表示使用身份验证,否则不使用身份验证.

$smtp-debug = FALSE; //是否显示发送的调试信息 TRUE发送 FALSE不发送

$smtp-sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);

sendMail.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; //密码

var $sock;

/* Constractor */

function smtp($relay_host, $smtp_port,$auth,$user,$pass)

{

// echo $relay_host." ".$smtp_port." ".$auth." ".$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");

}

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 CRLF.CRLF [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;

}

}

}

PHP使用邮箱发送邮件(phpmailer/phpmailer)

本文以QQ邮箱为案例

1.配置QQ邮箱,获取SMTP 密码

3.开启PHP模块(php.ini)

PHPMailer 需要 PHP 的 sockets 扩展支持,而登录 QQ 邮箱 SMTP 服务器则必须通过 SSL 加密,故 PHP 还得包含 openssl 的支持。

4.composer 安装最新版发送邮件类库

composer require phpmailer/phpmailer:6.1.5

TP5.1类库封装

请问这个发送邮箱PHP代码要怎么写

?php

require_once "Smtp.class.php";

//******************** 配置信息 ********************************

$smtpserver = "smtp.126.com";//SMTP服务器

$smtpserverport =25;//SMTP服务器端口

$smtpusermail = "new2008oh@126.com";//SMTP服务器的用户邮箱

$smtpemailto = $_POST['toemail'];//发送给谁

$smtpuser = "new2008oh";//SMTP服务器的用户帐号(或填写new2008oh@126.com,这项有些邮箱需要完整的)

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

$mailtitle = $_POST['title'];//邮件主题

$mailcOntent= "h1".$_POST['content']."/h1";//邮件内容

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

//************************ 配置信息 ****************************

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

$smtp-debug = false;//是否显示发送的调试信息

$state = $smtp-sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);

echo "div ";

if($state==""){

echo "对不起,邮件发送失败!请检查邮箱填写是否有误。";

echo "a href='index.html'点此返回/a";

exit();

}

echo "恭喜!邮件发送成功!!";

echo "a href='index.html'点此返回/a";

echo "/div";

?

结语:以上就是编程笔记为大家整理的关于邮箱接口怎么做php的全部内容了,感谢您花时间阅读本站内容,希望对您有所帮助,更多关于邮箱接口怎么做php的相关内容别忘了在本站进行查找喔。


推荐阅读
  • 由于php没有提供现成的smtp函数,却提供了一个功能不甚灵活的mail()函数,这个函数需要服务器配置上的支持,并且不支持smtp验证,在很多场合无法正常的工作,因此不建议使用。 ... [详细]
  • 本文介绍了一个React Native新手在尝试将数据发布到服务器时遇到的问题,以及他的React Native代码和服务器端代码。他使用fetch方法将数据发送到服务器,但无法在服务器端读取/获取发布的数据。 ... [详细]
  • Postgresql备份和恢复的方法及命令行操作步骤
    本文介绍了使用Postgresql进行备份和恢复的方法及命令行操作步骤。通过使用pg_dump命令进行备份,pg_restore命令进行恢复,并设置-h localhost选项,可以完成数据的备份和恢复操作。此外,本文还提供了参考链接以获取更多详细信息。 ... [详细]
  • 本文讨论了在使用PHP cURL发送POST请求时,请求体在node.js中没有定义的问题。作者尝试了多种解决方案,但仍然无法解决该问题。同时提供了当前PHP代码示例。 ... [详细]
  • 目录1、将mysql数据导出到SQL文件中(数据库存在的情况)2、将现有的sql文件数据导入到数据库中(前提数据库存在) 3、利用Navicat导出SQL文件和导入SQL文件1)从 ... [详细]
  • php设置数组大小_【大厂必备】2020超经典PHP面试题
    结合我自己这段时间的面试情况,面对的一些php面试题列举出来,基本上结合自己的看法回答的,不妥的地方请大家指出去,与大家一起 ... [详细]
  • ! Configuration File for keepalivedglobal_defs {   notification_email {     ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • 初始化初始化本地空版本库,仓库,英文名repositorymkdirtest&&cdtestgitinit克隆项目到本地gitclone远程同 ... [详细]
  • destoon会员注册提示“数据校验失败(2)”解决方法【PHP】
    后端开发|php教程destoon,会员注册,数据校验失败,后端开发-php教程很多人在使用destoon建立一个B2B系统的时候,会在企业站注册企业用户的时候出现:“数据校验失败 ... [详细]
  • 浅谈EditText控件的inputType类型
    其中大多数是用不到的,这里总结一下常用的几种键盘效果1、numberDecimal(可以带小数点的浮点格式)只可以输入0-9数字和小数点,即只浮点数2、number(数字格式 )只 ... [详细]
  • 【基础部分】之SMTP相关配置
    SMTP一、准备工作修改两个主机的主机名1.mailqq.qq.com2.mail163.163.com先配置dns邮件域名在mailqq.qq.com主机上配置dns配置etcn ... [详细]
author-avatar
冰忆ch
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有