We help IT Professionals succeed at work.
Get Started

Php form not sending notification

Last Modified: 2012-08-21
I have a newsletter sign up form which isn't quite working correctly.

I need it so the user submit their email, they recieve a 'thanks for registering....' email and another is sent to the website owner ie enquiries@business.co.uk.

Currently with the code below the user gets the email intended for the site owner which just says  "new registration: user email" and the site owner gets nothing?

 <form method="post" action="?">
                  <span class="keepuptodate">Keep up-to-date with the latest from Summit:</span>
                  <input name="email" type="text" class="left5" value="enter your email address" size="23" />
                  <input name="submit" type="submit" value=" " style="width: 110px; height: 28px; border: 0px; outline: 0px; padding: 0px;background: url(images/subscribe.jpg) no-repeat; cursor: pointer;" align="bottom" />
if ($error) {
	echo '<font color="red">'.$error.'</font>';
                  <span class="message">
//set up for email info
$strTo = enquiries@business.co.uk'; //your email here
$strSubject = 'Newsletter Sign up'; //default subject 
$strBody = '';

if ($_POST['submit']) {
	$strEmail = trim($_POST['email']);

	//both fields are required 
	if (!$strEmail) {
		$error = 'Please input both field!<br />';
	//elseif () {//extra validate should be here. eg: validate email address
	else {
		//prepare mail body
		$strBody = <<<BODY
New registration
Email: {$strEmail}

		//send email
		@mail ($strTo, $strSubject, $strBody,
     "From: ".$strTo."\r\n" .
     "Reply-To: ".$strTo."\r\n" .
          "X-Mailer: PHP/" . phpversion());
	 //prepare mail body
$strBody = <<<BODY
Many thanks for subscribing to our Newsletter.

If we can be of assistance in the mean time please do not hesitate to call us 

//send email
@mail ($strEmail, $strSubject, $strBody,
"From: ".$strTo."\r\n" .
"Reply-To: ".$strTo."\r\n" .
"X-Mailer: PHP/" . phpversion());

		//display message
		echo 'thanks for registering!';

Open in new window

Watch Question
Most Valuable Expert 2017
This problem has been solved!
Unlock 4 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE