Solved

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

Posted on 2014-03-31
5
4,440 Views
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:

<?

$name=$_POST['customername'];
$email=$_POST['email'];
$phone=$_POST['telephone'];
$message=$_POST['message'];

$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?

Thanks

Simon
0
Comment
Question by:cybersi
  • 3
  • 2
5 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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."
0
 

Author Comment

by:cybersi
Comment Utility
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?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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.
http://php.net/manual/en/function.mail.php

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:
http://www.faqs.org/rfcs/rfc2822.html

If you're new to PHP and you want to get a foundation, this article can help.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 

Author Comment

by:cybersi
Comment Utility
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

http://www.merlin-estates.com/contact-us.html

Thanks

Simon
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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" />
  </p>
  <p>
    <label for="telephone">Telephone number:</label>
    <input type="text" name="telephone" id="telephone" />
  </p>
  <p>
    <label for="email">Email Address:</label>
    <input type="text" name="email" id="email" />
  </p>
  <p>
    <label for="message" >Message:</label>
    <textarea name="message" rows="10" cols="20" id="message"></textarea>
  </p>
  <p>
    <input type="submit" name="contactus" class="noti contactbtn" value="" />
  </p>
</form>

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
0

Featured Post

Too many email signature updates to deal with?

Do you feel like you are taking up all of your time constantly visiting users’ desks to make changes to email signatures? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now