电子邮件和Web在不同服务器上分开:通过PHP将电子邮件发送到该域中的电子邮件 [英] Email and Web split on different servers: Send email via PHP to an email on that domain

查看:111
本文介绍了电子邮件和Web在不同服务器上分开:通过PHP将电子邮件发送到该域中的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1个在DNS上拆分了port80和MX的域:

1 Domain that has port80 and MX split on the DNS:

  • 网站托管在VPS上.
  • 电子邮件托管在共享主机上.

当我在网站上以域中的电子邮件地址调用PHP中的mail()函数时,该电子邮件将直接发送到VPS,而不是共享服务器.

When I call the mail() function in PHP on the website that is addressed to an email on the domain, the email is delivered LOCALLY to the VPS and not to the shared server.

在使用域MyDomain.com在Web主机VPS上运行的PHP中:

In PHP running on the web host VPS using the domain MyDomain.com:

$headers = "From: MyName <name1@MyDomain.com>\r\n";
$headers .="Return-Path:<name1@MyDomain.com>\r\n";
mail( "name2@MyDomain.com", "Header", "Content", $headers);

如何强制mail()对域进行MX查找?如何将电子邮件传递到共享主机而不是VPS?

How do I force mail() to do a MX lookup for the domain? How do I get the email delivered to the shared host and not the VPS?

我试图这样做,但是没有用:

I tried to do this but it didn't work:

ini_set("SMTP","123.456.789.012");

其中123.456.789.012是共享主机的IP.

Where 123.456.789.012 is the ip to the shared host.

共享主机是hostmonster.有没有一种方法可以使用ip和用户名指定电子邮件箱?名称2〜用户名@ 123.456.789.012

Shared host is hostmonster. Is there a way to specify the email box using the ip and username? name2~username@123.456.789.012

推荐答案

将mail()函数拖放为

Drop the mail() function in favor of PHPMailer. It is way more flexible, is object oriented, much easier to configure with SMTP and has much better attachments support (if you need it).

要在phpmailer中发送电子邮件,您只需要这样设置SMTP:

To send your email in phpmailer you'll just need something like this to set your SMTP:

$mailer = new PHPMailer();
$mailer->Mailer = 'smtp';
$mailer->Host = '123.456.789.012';
$mailer->From = 'me@myself.com';
$mailer->FromName = 'Me Myself';
$mailer->AddAddress = 'someRecipient@whatever.com';
$mailer->Subject = 'My subject line';
$mailer->Body = 'Your Body text here, in HTML if you set $mailer->IsHtml(true)';
$mailer->Send();

这篇关于电子邮件和Web在不同服务器上分开:通过PHP将电子邮件发送到该域中的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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