问题描述
我一直在尝试利用 jquery 可联系插件(在 google 上找到!)中的 mail.php 文件在我的网站上使用.尽管提供的脚本相当简单,但我在将其与主机的 SMTP 要求集成时遇到了问题.这是没有 SMTP 身份验证的原始脚本:
<p><strong>姓名:</strong>$name <br/><strong>电子邮件:</strong>$emailAddr <br/><strong>问题:</strong>$问题 </p><p><strong>消息:</strong>$comment </p><p><strong>发送IP:</strong>$_SERVER[REMOTE_ADDR]<br/><strong>发送方式:</strong>$_SERVER[HTTP_HOST]</div>";//发送并检查消息状态$response = (mail('mymail@mymail.com', $subject, $contactMessage, $headers) ) ?成功":失败";$output = json_encode(array("response" => $response));header('content-type: application/json; charset=utf-8');回声($输出);?>我尝试使用来自 Google 的建议并玩了几个小时.这是迄今为止基于我对 php 的零理解的最新版本.-__- (基于此:http://blog.geek4support.com/php-mail-script-with-smtp-authentication-how-to-send-mails-by-php-mail-script-using-smtp-authetication/)
<p><strong>姓名:</strong>$name <br/><strong>电子邮件:</strong>$emailAddr <br/><strong>问题:</strong>$问题 </p><p><strong>消息:</strong>$comment </p><p><strong>发送IP:</strong>$_SERVER[REMOTE_ADDR]<br/><strong>发送方式:</strong>$_SERVER[HTTP_HOST]</div>";$smtp = Mail::factory('smtp',数组('主机' => $主机,'认证' =>真的,'用户名' =>$用户名,'密码' =>$密码));$response = ($smtp->send('mymail@mymail.com', $subject, $contactMessage, $headers)) ?成功":失败";$output = json_encode(array("response" => $response));header('content-type: application/json; charset=utf-8');回声($输出);?>我实际上遇到了一些问题.我的主机不支持 PHPMailer :-(.只有带有 SMTP 的 PearMail.他们建议调整上面列出的代码并将我现有的代码与它合并.确切地说,在在线发布之前我一直在尝试做的事情.回到广场1、有什么想法吗?
评论,建议,任何东西都将不胜感激!:-)
解决方案 对于发送邮件,试试 PHPMailer,它已经过测试,每个人都在使用它,而且它可以正常工作.它还具有许多功能和配置选项.
最新版本是这个,至于发送使用带有 PHPMailer 的 SMTP 发送邮件,这就是您需要的所有代码
//POST 请求收到的数据$name = stripcslashes($_POST['name']);$emailAddr = stripcslashes($_POST['email']);$issue = stripcslashes($_POST['issue']);$comment = stripcslashes($_POST['message']);$subject = stripcslashes($_POST['subject']);//发送邮件$mail = 新 PHPMailer();$mail->IsSMTP();//告诉类使用 SMTP//SMTP 配置$mail->SMTPAuth = true;//启用 SMTP 认证$mail->Host = "我的主机";//SMTP 服务器$mail->用户名 = "你的用户名@gmail.com";$mail->Password = "你的密码";//$mail->端口 = 465;//如果您不想使用默认值,则可选$mail->From = "my@email.com";$mail->FromName = "我的名字";$mail->主题 = $主题;$mail->AltBody = "要查看邮件,请使用与 HTML 兼容的电子邮件查看器!";//可选,注释掉并测试$mail->MsgHTML($issue . "<br/><br/>" . $comment);//添加任意数量$mail->AddAddress($emailAddr, $name);//如果你想附加一个文件,它的相对路径//$mail->AddAttachment("images/phpmailer.gif");//依恋$响应=空;if(!$mail->Send()) {$response = "邮件错误:" .$mail->错误信息;} 别的 {$response = "消息已发送!";}$output = json_encode(array("response" => $response));header('content-type: application/json; charset=utf-8');回声($输出);
I've been trying to utilize a mail.php file from the jquery contactable plugin (found on google!) to use on my website. Although the script provided is fairly simple I'm running into issues with integrating it with my Host's SMTP requirement. Here is the original script without SMTP authentication:
<?php
// Assign contact info
$name = stripcslashes($_POST['name']);
$emailAddr = stripcslashes($_POST['email']);
$issue = stripcslashes($_POST['issue']);
$comment = stripcslashes($_POST['message']);
$subject = stripcslashes($_POST['subject']);
// Set headers
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
// Format message
$contactMessage =
"<div>
<p><strong>Name:</strong> $name <br />
<strong>E-mail:</strong> $emailAddr <br />
<strong>Issue:</strong> $issue </p>
<p><strong>Message:</strong> $comment </p>
<p><strong>Sending IP:</strong> $_SERVER[REMOTE_ADDR]<br />
<strong>Sent via:</strong> $_SERVER[HTTP_HOST]</p>
</div>";
// Send and check the message status
$response = (mail('mymail@mymail.com', $subject, $contactMessage, $headers) ) ? "success" : "failure" ;
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
?>
I've tried using suggestions from Google and played around with it for hours. Here is the latest version based on my nil-understanding of php thus far. -__- (Based on this: http://blog.geek4support.com/php-mail-script-with-smtp-authentication-how-to-send-mails-by-php-mail-script-using-smtp-authetication/)
<?php
require_once "Mail.php";
// Assign contact info
$name = stripcslashes($_POST['name']);
$emailAddr = stripcslashes($_POST['email']);
$issue = stripcslashes($_POST['issue']);
$comment = stripcslashes($_POST['message']);
$subject = stripcslashes($_POST['subject']);
$host = "mail.mywebsite.com";
$username = "mywebsitemail@mywebsiteaddress.com";
$password = "mymailpassword";
// Set headers
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
// Format message
$contactMessage =
"<div>
<p><strong>Name:</strong> $name <br />
<strong>E-mail:</strong> $emailAddr <br />
<strong>Issue:</strong> $issue </p>
<p><strong>Message:</strong> $comment </p>
<p><strong>Sending IP:</strong> $_SERVER[REMOTE_ADDR]<br />
<strong>Sent via:</strong> $_SERVER[HTTP_HOST]</p>
</div>";
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$response = ($smtp->send('mymail@mymail.com', $subject, $contactMessage, $headers)) ? "success": "failure";
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
?>
I've actually run into a bit of a problem. My host doesn't support PHPMailer :-(. Only PearMail with SMTP. They have suggested tweaking the code listed above and incorporating my existing one with it. Exactly, what I've been trying to do before posting this online. Back to square 1, any ideas?
Comments, suggestions, anything would be most appreciated! :-)
解决方案 For sending mails, try PHPMailer, it's tested, everybody uses it, and it just works.
It also has a lot of features and configuration options.
The latest version is this one, as for sending mails using SMTP with PHPMailer this is all the code you need
// Data received from POST request
$name = stripcslashes($_POST['name']);
$emailAddr = stripcslashes($_POST['email']);
$issue = stripcslashes($_POST['issue']);
$comment = stripcslashes($_POST['message']);
$subject = stripcslashes($_POST['subject']);
// Send mail
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
// SMTP Configuration
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "myhost"; // SMTP server
$mail->Username = "yourusername@gmail.com";
$mail->Password = "yourpassword";
//$mail->Port = 465; // optional if you don't want to use the default
$mail->From = "my@email.com";
$mail->FromName = "My Name";
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($issue . "<br /><br />" . $comment);
// Add as many as you want
$mail->AddAddress($emailAddr, $name);
// If you want to attach a file, relative path to it
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
$response= NULL;
if(!$mail->Send()) {
$response = "Mailer Error: " . $mail->ErrorInfo;
} else {
$response = "Message sent!";
}
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
这篇关于邮件.php &SMTP 身份验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End
相关推荐
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20
php开发问题
168
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23
php开发问题
287
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23
php开发问题
11
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23
php开发问题
4
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23
php开发问题
17
热门文章
1nohup:忽略输入并将输出附加到“nohup.out"
2在控制台中出错:无法加载资源:net::ERR_CONNECTION_RESET
3如何将 LDAP 时间戳转换为 Unix 时间戳
4不推荐使用常量 FILTER_SANITIZE_STRING
5APACHE 崩溃:父进程:子进程以状态 3221225477 退出 -- 正在重新启动
6PHP通过phpspreadsheet导入Excel日期数据处理方法
7Analytics API 返回:错误请求 - invalid_grant
8“tlsv1 警报内部错误"握手时
热门精品源码
最新VIP资源
1多功能实用站长工具箱html功能模板
2多风格简历在线生成程序网页模板
3论文相似度查询系统源码
4响应式旅游景点宣传推广页面模板
5在线起名宣传推广网站源码
6酷黑微信小程序网站开发宣传页模板
7房产销售交易中介网站模板
8小学作业自动生成程序


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)