Generate a auto response  email using PHP that is from no-reply@domain.com

Posted on 2014-03-31
Medium Priority
Last Modified: 2014-05-02
Hi PHP developers

I have a script that is part of my contact page on my web site. Basically the script sends a email to hosted mail box then forwards the email to a distribution group on a exchange server as shown below:



$emailBody =   "Name: ".$name."\nEmail: ".$email."\nPhone: ".$phone."\n\nMessage: \n\n".$message."\n";                                

$headers = 'From: info@domain.com' . "\r\n" .
    'Reply-To: info@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail('info@domain.com', 'Email from Website', $emailBody, $headers);

header('Location: ../contact-thanks.html');

What I would like to do is by pass the hosted server and delivery directly to exchange 2010 mailbox which has forwarding setup to a distribution group all ready setup on the exchange server.

I have created the mailbox web@domain.com and forwarding to the distribution group but what I would really like is the php script to send a No-reply email back to the sender thanking them etc maybe a link for more help.

Anyone got any ideas on the best way to achieve this?

In addition would I need to create a spf record to achieve this?


Question by:cybersi
  • 3
  • 2
LVL 111

Expert Comment

by:Ray Paseur
ID: 39966691
I'm not completely clear on what you want but I think I might have an idea.  Let me try to paraphrase...

When emails are received at a certain address, they are to be processed automatically on your server.  The automatic processing should include, inter alia, a response to the sender.  The automatic processing would include forwarding to the distribution list.

Does that capture the idea?  If so, you might want an "email pipe."

Author Comment

ID: 39967958
Hi Ray
In a nut  shell I would like to add to my php script to send a no reply email if it can be done?
LVL 111

Expert Comment

by:Ray Paseur
ID: 39969259
You can send an email message from within a PHP script.  All contents of the email can be made up by you (that is one of the problems with email -- no accountability).  You use this function.

Since there are several layers of technology involved in sending email you would want to set up some tests, paying close attention to the headers that your server creates.  You can specify some of the headers, as shown in the online documentation about additional_headers.  The "From" address is one of the additional headers.

You may also want to familiarize yourself with this:

If you're new to PHP and you want to get a foundation, this article can help.

Author Comment

ID: 39969506
Hi Ray

You guessed it I have zip knowledge when it comes to PHP.  What I would like to do is capture the email address from the above field and then send a auto response to the captured email address thanking them and providing a link to a search facility I have on my web site.  So I need the capture and send email elements to be added to the above script. As it stands the script obviously already sends me an email with information from this page



LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 39970653
In the generated source code for the contact-us page, the form starts on line 262.  Stripped of fluff and formatting it looks more or less like this:

<form action="scripts/mail.php" method="post" id="contactform">
  <p class="nm">
    <label for="customername">Name:</label> 
    <input type="text" name="customername" id="customername" />
    <label for="telephone">Telephone number:</label>
    <input type="text" name="telephone" id="telephone" />
    <label for="email">Email Address:</label>
    <input type="text" name="email" id="email" />
    <label for="message" >Message:</label>
    <textarea name="message" rows="10" cols="20" id="message"></textarea>
    <input type="submit" name="contactus" class="noti contactbtn" value="" />

Open in new window

The HTML form will be submitted to the URL of the action= attribute of the form tag.  This is scripts/mail.php.  The email address is expected to be found in the PHP variable named $_POST['email'].  It will be there because this is a POST-method request and the form contains an input control with name="email".  The name in the form input control is the name that is used for the array element in the request array.

Your server-side automation will need to filter the request array and determine if the data is suitable for further use.  For example, you will need to decide if the email address is acceptably formatted and if the address is routable.  Since this is external data, your PHP script must work under the assumption that the data is tainted and is an attack vector.  The rule here is "accept only known good values."

When you start capturing email addresses and sending out messages one of the first things that is going to happen is that a hacker will discover your form and will start sending honeypot addresses to the form.  Your script will, in turn, send automated email messages to the honeypots and you'll quickly be branded a spammer.  Your hosting company may shut you down.  And there may even be criminal penalties involved (in the USA you can get prison time for something like this).  So you will want to have some way of controlling who can put information into the form.  A good way to prevent an automated attack is with a CAPTCHA test.

As you may have guessed by now, there are a lot of moving parts to something like this.  You might want to consider hiring a professional PHP programmer to help you with the implementation details.  It's not a big job, but there are so many nuances and subtle risks that it's very easy to get something wrong.  A pro would have been through those risks before and would have ways of mitigating the risks.  Just a thought... ~Ray

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Are you working to mount the dismounted Exchange 2013 database? Then the best course of action is to analyze the causes of Database issue, their probable solutions and decide for the appropriate course of action.
Microsoft Exchange Server gives you the ability to roll back a corrupt database, but still preserve any data written to that database since the last successful backup. Unfortunately the documentation on how to do this when recovering using imaging b…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…

584 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question