Jump to content

Why is Godaddy's linked outlook account not receiving emails from my php contact form?


Recommended Posts

Hi there. I'm working on my first web contract for a client. We switched to Godaddy, and he wants to use the linked Outlook account that comes with it. Unfortunately, the php contact form I created, doesn't seem to be going through to Outlook. The contact form successfully sends emails to the roundcube webmail, and to gmail. I've also tried email forwarding using roundcube to Outlook, but I still can't receive any emails.

Some research about this seems to indicate I need to modify SPF or DNS settings. Is this true, or any advice on how I can get this working?

Thanks for reading.

 

Link to comment
Share on other sites

This seems like something GoDaddy should provide you support with, since they are apparently reselling office365 hosted email to your client.

Roundcube is a web based IMAP client, so it's unclear from your description what that connects to.  Is it bundled goddaddy email, or direct to office365? 

Here is what I can tell you about email delivery:  it is exceedingly complicated and requires a lot of knowledge and complete administrative control for a domain and any related servers.   You aren't going to get DKIM setup on a hosted server.  You *might* be able to set it up on a virtualhost if you really know what you're doing.  It's not unlike networking, for which you can have much general understanding, but still not enough to pull off what a network engineer does.  SPF alone is not enough to get deliverability these days.

With that said, we have no idea what sort of account you are using, nor did you explain what the mailing code is.  For example, most people have been using phpmailer to handle the sending of emails.  Is that what you are doing?

What configuration did you utilize in your form?  Who do the emails come from?  

In terms of SPF, again Godaddy should have provided the instructions you need, but this is complicated by the fact that it sounds like in this case your email service is coming from Office365.  So what you typically need then, is configuration of an SPF record that essentially delegates the SPF to Office65 (since they would be the MX of record for your domain).

You also would need to have phpmailer configured so that emails go directly from phpmailer (which will use some form of SMTP connection) to their server infrastructure.  In other words, if your email is hosted by Microsoft, then you want to deliver it directly to microsoft (and it will use the credentials and security they support).  

In that case, it's basically dropping mail directly into Microsoft's email system.  It's surprising to me that whatever you are currently doing doesn't get you to office365 but does get you to gmail, as they both are pretty rigorous in not accepting or spam filtering emails that don't qualify as doing everything that legitimate email servers expect these days.

Link to comment
Share on other sites

Okay, then, before we go further. I'm using the mail() function. I'm still learning php, but I'm doing the best I can.  Sounds like, from my research, I'll have to use phpmailer, and somehow modify my form to work with phpmailer instead of using the mail() function. Not sure, but my client wants to use it, and it seems it's the only way he can transfer his old emails. I tried customer support, but after two hours, they just said that everything is working on their end, they can't help me with Outlook since it's not 'their end' and that I'd have to contact Outlook customer service, even though there's no such thing.

Here's the code, by the way:

 


<?php

// define variables and set to empty values
$name = $email = $phone = $city = $subject = "";
$nameErr = ""; $emailErr = ""; $phoneErr = ""; $subjectErr = "";
$sent = "";
 
$to = 'example@example.com';
$message= '';
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$subject = $_POST['subject'];


      foreach ($_POST as $key => $value) {
$message .= '<strong>' . ucfirst($key) ."\r\n" . '</strong>' . ': '  . $value . '<br>' . PHP_EOL;
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = test_input($_POST["name"]);
  $email = test_input($_POST["email"]);
  $phone = test_input($_POST["phone"]);
  $city = test_input($_POST["city"]);
  $subject = test_input($_POST["subject"]);
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . "From:" .$name ."<" .$email ."\r\n";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "From: example@example.com\r\n";



if ($_SERVER["REQUEST_METHOD"] == "POST" AND empty($_POST["name"])) {
    $nameErr = "Name is required";
  }
  if ($_SERVER["REQUEST_METHOD"] == "POST" AND empty($_POST["email"])) {
    $emailErr = "Email is required";
  }
  if ($_SERVER["REQUEST_METHOD"] == "POST" AND empty($_POST["subject"])) {
    $subjectErr = "Subject is required";
  }
  
    if ($_SERVER["REQUEST_METHOD"] == "POST" AND !(preg_match("/^[a-zA-Z-' ]*$/",$name))) {
    $nameErr = "Name cannot contain any special characters";
  }
  
  if ($_SERVER["REQUEST_METHOD"] == "POST" AND !filter_var($email, FILTER_VALIDATE_EMAIL)) {
  $emailErr = "Invalid email format";
}
  
if ($_SERVER["REQUEST_METHOD"] == "POST" AND !empty($_POST["name"]) AND !empty($_POST["email"]) AND !empty($_POST["subject"]) AND (preg_match("/^[a-zA-Z-' ]*$/",$name)) AND (filter_var($email, FILTER_VALIDATE_EMAIL))) {
mail($to, $subject, $message, $headers);
$sent = '<div class="sent-message">'. "Thankyou for contacting us!". '</div>';
}

?>

I didn't include the actual html form below the php, since it's for my client and has his website info, but I can include it if it helps.
 

Link to comment
Share on other sites

We do get these type of questions regularly.   If you look at the code for this person it will give you a good idea of how you would utilize phpmailer.  The basic mail() function -- I don't want to write up a manual on it, but it has a few different possible modes, although in general it's not what you want to use here.  Probably it is dumping mail to GoDaddy's servers, which also aren't setup to be the MX for the customer's domain.  So you have a few different options here:

  • Change everything so GoDaddy is hosting email for the domain
  • Use the current mail exchanger (assuming it's Microsoft right now).
  • You may need to be able to modify/make changes to the customer's DNS entries for their domain, depending on how things currently work, and whether or not you want to change.

Here is a fairly recent thread:  

 

So, again I'm still not clear on the moving parts here, but I can tell you what is feasible.

Things you need to clarify:

  • For the customer's domain, who is hosting mail?
    • In DNS entries, this is the company/servers that are accepting mail for the domain
      • Is this Outlook/aka Office365?  Keep in mind these are different brand names for Microsoft hosted email.  It also includes Hotmail or used to.
      • When you say that the client uses Outlook, we need to be clear.  Anyone can use outlook with any system.  I can setup outlook to work with a domain I personally own, that is a fully functional self hosted email system if I want to, because outlook supports IMAP, and I provide IMAP services for my domain(s). With that said, as part of office, Outlook is very popular in a lot of corporate "all microsoft" shops because it has built in support for Active Directory, exchange, and microsoft networking and file services that many companies use.  IMAP includes integration with things like calendering, which is another reason people tend to like it.
        • I also understand if they don't want to change from (whatever they have now) because emails are stored on whatever server they are using now.  Changing to use Godaddy's server could work with Outlook, but all the mail that was on the old server would be gone.
          • Email could be moved in a variety of ways, but with only client access, it could be a time consuming and error prone process if they have a large number of emails being stored.
    • Because I don't know the facts, I can only guess at the obstacles, and options.
      • Again, *if* current business email for the customer's domain is being hosted by microsoft, then the path of least resistance is to determine the protocol and credentials needed to setup SMTP mail delivery into the customer's system.
        • This involves something like:  configuring the phpmailer configuration settings to use smtp, along with TLS, and a user name and password for the account(s) they pay for from microsoft as part of their email hosting.
        • Once you set this in phpmailer, you make the to: be that account (ie. From: user@customerdomain.com, and then To: is customer.  If this was working previously, as I said, any mail sent directly to the same user (same to/from) stays in microsoft's system and goes right into their box.  
        • Most of these systems also allow aliases to be created, so typically a different user alias like system@domain.com can be setup within the microsoft configuration for the hosted account, and you could instead have phpmailer configured to send mail from that address rather than person@domain.tld

 

I think I'm going to leave it at this now, as I still have way too many frustrating questions about this, and the various branding of microsoft products and services with overlapping names doesn't help.  Given everything I've written, there could be an entirely different set of factors at play here, and without detailed and specific information about the domain MX record as well as any other entries like SPF, there's really no way for us to help you further other than just guessing.

Link to comment
Share on other sites

29 minutes ago, DeclineoftheWest said:

Okay, I will learn phpmailer instead of using mail() and attempt to rewrite my previous code to replace phpmailer with the mail function and go over the previous thread before asking further. Thank-you.

Perfect approach.  If you would like me to answer some of the domain questions for you, feel free to PM me the domain and I'll search the DNS and determine what services are being used, if you are having trouble figuring that out.  Either way I think you are on the right track.  With that said you need to understand how to install and require the phpmailer libraries.  Typically people will use composer to install the library.  It can be downloaded and specified manually, but you will notice in that code namespaces, which if you are new to PHP maybe over your head.  They are very important these days, and you'll see looking at that other thread, that the libraries are referenced at the top with use statements.  Those are not magic without either include/requiring the individual files, or using an autoloader script (which is part of what composer will do for you --- generate an autoload.php script you can include. 

If you use the autoloader, then you don't need anything other than the use statements, as PHP understands how to look for and locate the library source scripts.  You might already know all this, but if you don't, this is why the php composer tool is pretty much essential to professional php development these days.  It provides dependency management and location and setup of 3rd party/component libraries like phpmailer.  I would highly recommend that at least for this script, this is how you integrate phpmailer into your script.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.