在IIS7上设置phpmailer [英] Setting up phpmailer on iis7

查看:151
本文介绍了在IIS7上设置phpmailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从Windows共享托管转移到了VPS.我正在努力让phpmailer在我的网站上为联系表单工作.

I recently moved from windows shared hosting to a VPS. I'm struggling to get phpmailer to work for a contact form on my website.

设置电子邮件发送给我的网站的代码为:

The code for my site the sets up the email to send is:

$mail->IsSMTP(); // set mailer to use SMTP 
 $mail->Host = "smtp.gmail.com"; // specify main and backup server or localhost 
 $mail->SMTPAuth = true; // turn on SMTP authentication 
 $mail->SMTPSecure = "tls"; 
 $mail->SMTPDebug = 1; // can vary the amount of debug info given on error 
 $mail->Username = "mail@mydomain.com"; // SMTP username 
 $mail->Password = "########"; // SMTP password 
 $mail->Port = 587;

此代码在旧的Windows共享托管上有效.另外,其他所有内容也与网站相同(class.phpmailer.php文件等)

This code worked on the old windows shared hosting. Also everything else is identical too with the site (the class.phpmailer.php file etc)

所以我猜测这与iis或服务器本身的设置有关.

So I'm guessing it's something to do with my setup of iis or the server itself.

根据我为我检查过的Web主机,在587端口上进行连接工作

Connecting out works on port 587 according to my webhosts who checked that for me

我使用可为您完成所有工作的Microsoft工具安装了php.该网站位于php中,并且可以正常工作,在我看来,未经训练的人看上去都还不错.

I installed php using the Microsoft tool that does everything for you. the site is in php and is working, and it looks to my untrained eye like all is fine there.

我已经检查了php_openssl.dll是否已启用.

I've checked that php_openssl.dll is enabled.

我花了很长时间阅读和摆弄,没有运气.接下来的内容我真的很茫然.有什么想法可能是什么,或者我应该尝试什么?

I've spent a long time reading around and fiddling with no luck. I'm really at a loss as what to look at next. Any ideas what it could be or what I should try?

谢谢!

菲尔.

php表单上的操作是转到contactprocessor.php.

The action on the php form is to go to contactprocessor.php.

该文件包含以下代码:

<?

ob_start();



if(isset($_POST['btnSubmit']))
{
require("class.phpmailer.php");



$mail = new PHPMailer();

//Your SMTP servers details

$mail->IsSMTP();               // set mailer to use SMTP
$mail->Host = "smtp.gmail.com";  // specify main and backup server or localhost
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->SMTPSecure = "tls"; 
$mail->SMTPDebug = 1; // can vary the amount of debug info given on error
$mail->Username = "mail@mydomain.com";  // SMTP username
$mail->Password = "########"; // SMTP password
$mail->Port = 587;


$redirect_url = "http://www.mydomain.com/contact/contact_success.php"; //Redirect URL after submit the form

$mail->From = $mail->Username;  //Default From email same as smtp user
$mail->FromName = "Website Contact Form";

$mail->AddAddress("mail@mydomain.com", "From Contact Form"); //Email address where you wish to receive/collect those emails.

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML



$mail->Subject = "From Contact Form";
$message = "FullName: ".htmlspecialchars($_POST['fullname'])." <br> <br> 
\r\n <br>EmailAddress: ".htmlspecialchars($_POST['email'])." <br> <br> 
\r\n <br>Phone Number: ".htmlspecialchars($_POST['mobile'])."  <br> <br> 
\r\n <br> Message: <br>".htmlspecialchars($_POST['message']);
$mail->Body    = $message;

if(!$mail->Send())
{
   echo "Sorry the message could not be sent. Please email mail@mydomain.com instead. Thanks<p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
header("Location: $redirect_url");
}
?>

似乎没有实际发送电子邮件,而是将上面的内容打印到用户的屏幕上,就像是一个网页一样.好像服务器认为它是一个html页面并正在提供它一样.

Instead of actually sending the email, it just seems to print the above to screen of the user as if it's a webpage. it's as if the server thinks it's a html page and is just serving it.

推荐答案

您写道:

似乎没有实际发送电子邮件,而是将上面的[code]打印到用户的屏幕上,就像是在打印网页一样.好像服务器认为它是一个html页面并正在提供它一样.

Instead of actually sending the email, it just seems to print the above [code] to screen of the user as if it's a webpage. it's as if the server thinks it's a html page and is just serving it.

我认为您的问题与phpMailer或电子邮件完全无关.

I think your problem is unrelated to phpMailer, or indeed email at all.

几乎可以肯定,这是新旧服务器上PHP配置之间的微小差异.

This is almost certain to be simply a small difference between the PHP configuration on your old and new servers.

您的PHP代码使用的是简短样式的PHP标记-即以<?开头.

Your PHP code is using the short-style PHP tags -- ie starting with <?.

许多PHP服务器配置为不允许使用此短样式标记,而仅运行以完整的<?php标记开头的PHP代码.

Many PHP servers are configured not to allow this short-style tag, and only run PHP code that starts with the full <?php tag.

鉴于您在我上面的发言中所说的话,我怀疑这是您的问题,因为您所描述的正是我所期望的症状.

Given what you stated in the remark I quoted above, I suspect this is your problem, because what you describe is exactly the symptom I would expect from that.

您有两个选择:

  1. 更改代码以使用长样式<?php标记.

更改服务器配置以允许使用简短的<?标签.

Change your server config to allow the short <? tag.

如果可能的话,我建议您采用选项(1),因为长格式标签被认为是最佳实践(不建议使用短格式标签,因为在大多数XML的开头,它可能与<?xml标记发生冲突文档).

I would recommend taking option (1) if possible, because the long-form tags are considered best practice (the short form is not recommended because it can have a potential clash with the <?xml marker at the start of most XML documents).

如果您有很多短格式的<?标签(并假设您被允许这样做),则更改服务器配置可能值得考虑,但是如果足够容易通过切换为长标签来解决此问题,我想那会更好.

If you have a lot of short-form <? tags (and assuming you're allowed to do so), changing the server config may be worth considering, but if it's easy enough to fix the problem by switching to long tags, I'd say that would be better.

希望有帮助.

这篇关于在IIS7上设置phpmailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆