Page 1 of 1

Newbie - code to send copy of web form to senders email too

Posted: Wed Oct 08, 2014 4:41 am
by trickslide
Hi
First time post. I have read online and there are so many different answers I do not know which to choose.
I have a form on a website which works fine as it is.

I just want to add a function that when the the visitor clicks submit they also get a copy of the email as well. I am not sure where to put a cc to the email address entered

This is the code I have:

Code: Select all

 <p>Please read through our terms of business below. If you are happy with them and understand them please complete your details and press the agree button. We will email confirmation of receipt</p>
 <div class="content_image">
 <img src="images/questionnaire.jpg" alt="" width="350" height="225" />
 </div>
 <form id="questionnaire" method="post" action="terms-of-business-send.php" name="questionnaire">
 <fieldset>
 <div>
 <label>Your Full Name:</label><br />
 <input type="text" id="c_name1" name="c_name1" class="qfield clear" />
 </div>
 <div>
 <label>Your Email:</label><br />
 <input type="text" id="email" name="email" class="qfield clear" />
 </div>
 <div>
 <label>Your Contact Tel:</label><br />
 <input type="text" id="tel" name="tel" class="qfield clear" />
 </div>
 </fieldset>
 <fieldset>
 <ol>
 <li>
 <h2>I agree I have read and understood the terms of business</h2>
 <input type="radio" name="q1" value="1" /> yes I agree<br />
 </li>
 </ol>
 <div>
 </div>
 </fieldset>

 <input type="submit" value="Agree">
 <input type="reset" value="Reset">
 <h4 id="error">There were errors on the form, please make sure your name and email have been filled out correctly.</h4>
 </form>

Then the send file is

Code: Select all

 <?php
 $c_name1 = $_POST['c_name1'];
 $email = $_POST['email'];
 $tel = $_POST['tel'];
 $q1 = $_POST['q1'];

 //$to = 'enquiries@email.net';
 $to = 'enquiries@cemail.net';
 $subject = 'Terms of Business Completed';
 $msg = "$c_name1 has completed a Terms of Business from.\n\n" .
 "Their email is: $email\n" .
 "Their contact number is: $tel\n" .

 "-----------------------------\n\n" .
 "1: $q1\n\n" .
 "Terms of business copy here" .

 "-----------------------------\n" .
 " END OF FORM -------\n" .
 "-----------------------------\n\n";

 mail($to, $subject, $msg, 'From: website Terms of Business Form');
 echo '<h2>Thanks for confirming our Terms of Business ' . $c_name1 . '</h2>';

 ?>
I kind of understand what is going on but am not proficient enough.

Any help much appreciated.

Rich

Re: Newbie - code to send copy of web form to senders email

Posted: Wed Oct 08, 2014 6:18 am
by Celauran
Add it to your email headers.

You already have

Code: Select all

mail($to, $subject, $msg, 'From: website Terms of Business Form');
So

Code: Select all

$headers = "From: website Terms of Business Form\r\n";
$headers .= "Cc: {$email}\r\n";
mail($to, $subject, $msg, $headers);

Re: Newbie - code to send copy of web form to senders email

Posted: Thu Oct 09, 2014 4:05 am
by trickslide
Thank you Celauran,

worked a treat. Easy when you know how.

all the best
Richard

Re: Newbie - code to send copy of web form to senders email

Posted: Fri Oct 31, 2014 5:51 am
by trickslide
Hi,

I have the above code and it is working of sorts.

I have realized that it is not sending the email to the cc address if it is hotmail, yahoo, bt.

Is there something I can add to help send through.

I think it may (but not sure) something to do with the email showing in the from line
username@servername on behalf of website terms of business.

Any help much appreciated

Re: Newbie - code to send copy of web form to senders email

Posted: Fri Oct 31, 2014 7:13 am
by Celauran
trickslide wrote:I have realized that it is not sending the email to the cc address if it is hotmail, yahoo, bt.
Not sending or not being received?

Re: Newbie - code to send copy of web form to senders email

Posted: Fri Oct 31, 2014 7:19 am
by trickslide
Hi thanks for the reply.

not being received.
The email shows up in the cc field that I receive but cc email address is not receiving the email.

I have filled the form in with my own personal email (not a hotmail, yahoo etc) and the email is received at both the $to email and the cc.

If i use a hotmail address in the form, the $to email receives it but the hotmail does not.

I hope that makes sense

Cheers
Richard

Re: Newbie - code to send copy of web form to senders email

Posted: Fri Oct 31, 2014 7:21 am
by Celauran
Shared webhosting? Have you checked that they aren't being diverted to spam? Checked your mail logs to see what's going on? Have you got SPF set up on your domain?

Re: Newbie - code to send copy of web form to senders email

Posted: Fri Oct 31, 2014 7:32 am
by trickslide
the one I am set up where I am testing is a shared account. I do not have a SPF setup as far as I know. I will log into cpanel and find the mail logs .

However the finished code if for a favour for a client and I am not sure if their website is on a shared host or not. Their email is dealt with separately by a dedicated IT company. I believe this IT company gave them some webspace, gratis as their last web company went bust.

Cheers
Richard