Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Suggested Courses

604 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