php contact form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wanjali
Forum Newbie
Posts: 3
Joined: Fri Jul 10, 2015 3:25 am

php contact form

Post by wanjali »

That's the code that I am using, but it is not working. Can anyone help?
In the form I am asking for name and email address to subscribe. But this is the error message that comes
PHP Warning: mail(): SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in D:\inetpub\vhosts\legalyaar.com\httpdocs\contact.php on line 9

Code: Select all

<?php
	
	$name = $_POST['name'];
	$email = $_POST['email'];
	$message = $_POST['message'];
	
	$formcontent="Name: $name\n\nEmail: $email\n\nMessage: $message";
	
	// Enter the email where you want to receive the notification when someone submit form
	$recipient = "anjali@legalyaar.com";
	
	$subject = "Comingsoon! Contact Form";
	
	$mailheader = "From: $email\\r\\n";
	$mailheader .= "Reply-To: $email\\r\\n";
	$mailheader .= "MIME-Version: 1.0\\r\\n";
	
	$success = mail($recipient, $subject, $formcontent, $mailheader);
	
	if ($success == true){
	
?>
	
	<script language="javascript" type="text/javascript">
		alert('Thank you for subscribing to our newsletters.');
		window.location = "../index.html";
	</script>
	
<?php
	
	} else {
	
?>

    <script language="javascript" type="text/javascript">
		alert('Message not sent.');
		window.location = "../index.html";
    </script>
	
<?php

    }
	
?>
Last edited by wanjali on Fri Jul 10, 2015 6:18 am, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php contact form

Post by requinix »

"it is not working" doesn't mean anything to us. How is it not working? What did you expect it to do and what did it actually do?

Code: Select all

$mailheader = "From: $email\\r\\n";
$mailheader .= "Reply-To: $email\\r\\n";
$mailheader .= "MIME-Version: 1.0\\r\\n";
Those backslashes must not be escaped. You do want the actual \r and \n characters in there.
smithedison
Forum Newbie
Posts: 9
Joined: Fri Jul 10, 2015 4:51 am

Re: php contact form

Post by smithedison »

may i know what actually error you seen whenever you run this program
wanjali
Forum Newbie
Posts: 3
Joined: Fri Jul 10, 2015 3:25 am

Re: php contact form

Post by wanjali »

Sorry, I am new to this. Thanks for letting me know how it works here.

I expected this code to let a person subscribe to my email list by entering name & email. However it is giving the said error... and not sending a mail with the information entered by the user.
requinix wrote:"it is not working" doesn't mean anything to us. How is it not working? What did you expect it to do and what did it actually do?

Code: Select all

$mailheader = "From: $email\\r\\n";
$mailheader .= "Reply-To: $email\\r\\n";
$mailheader .= "MIME-Version: 1.0\\r\\n";
Those backslashes must not be escaped. You do want the actual \r and \n characters in there.
wanjali
Forum Newbie
Posts: 3
Joined: Fri Jul 10, 2015 3:25 am

Re: php contact form

Post by wanjali »

Error message
PHP Warning: mail(): SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in D:\inetpub\vhosts\legalyaar.com\httpdocs\contact.php on line 9






requinix wrote:"it is not working" doesn't mean anything to us. How is it not working? What did you expect it to do and what did it actually do?

Code: Select all

$mailheader = "From: $email\\r\\n";
$mailheader .= "Reply-To: $email\\r\\n";
$mailheader .= "MIME-Version: 1.0\\r\\n";
Those backslashes must not be escaped. You do want the actual \r and \n characters in there.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php contact form

Post by Celauran »

I see you're using Windows, which doesn't have a built-in mail server. Do you have a mail server configured or have you configured the SMTP settings for PHP?
Post Reply