Jump to content

problem with contact page in my website(don't send email)


sonita

Recommended Posts

Hello

I have a website & upload this in internet and this links is a url for mywebsite

http://www.keivanstone.ir

 

i have a contact page and a contact's form inside this page but I would fill all fields and submit button, I can not be emailed.'s This?

What do I have to be true. And the user is able to send email.
this code is a my contact page
     <?php$php_self = $_SERVER['PHP_SELF'];//$error_name = " you don't enter name.please enter you name.";// on submit$mail_sent=0;$error_name = $error_email = $error_subject=$error_body = $error_captcha = '';if( isset($_POST['name']) && isset($_POST['email'])&&isset($_POST['subject']) && isset($_POST['body']) && isset($_POST['captcha']) ){    $name = $_POST['name'];    $email = $_POST['email'];	$subject = $_POST['subject'];    $body = $_POST['body'];    $captcha = $_POST['captcha'];           $error = 0;    // name    if( $name == "" ){ $error ++; $error_name = "class='error'"; }    // email    if( $email == "" ){ $error ++; $error_email = "class='error'"; } 	// subject    if( $subject == "" ){ $error ++; $error_subject = "class='error'"; }    // body    if( $body == "" ){ $error ++; $error_body = "class='error'"; }    // captcha    if( $captcha == "" || $captcha != $_SESSION['captcha']){ $error ++; $error_captcha = "class='error'"; }       // no error, send email    if( $error == 0){                                                // your email address        $address = "info@keivanstone.ir";                   // email subject        $subject = "New body";        // email content        $content = "نام:$nameپست الکترونیک:پیام شما:$email$body";        // html email        $email_content = "<!doctype html><head><meta charset='utf-8'><title>".$subject."</title>";        $email_content .= "</head><body>";        $email_content .= $content;        $email_content .= "</body></html>";                                              // headers for html email        $headers  = 'MIME-Version: 1.0' . "/r/n";        $headers .= 'Content-type: text/html; charset=utf-8' . "/r/n";        $headers .= "From: info@keivanstone.ir <>" . "/r/n";        // send email        mail($address, $subject, $email_content, $headers);                          // reset variables        $name = ""; $email = ""; $body = "";        $mail_sent = 1;                                                               }}else{    $name = $email = $subject= $body = $captcha = ''; }// captcha$num = rand(1, 40);$num2 = rand(5, 25);   $verif = $num . "+" . $num2;$_SESSION['captcha'] = $num . $num2;       if( $mail_sent == 1 ){    echo "<h1>از تماس شما سپاسگزاریم.تا48 ساعت آینده پاسخ خود را دریافت خواهید کرد.<br/>گروه سنگ آنتیک کیوان</h1>";} else {    echo "    <form action='".$php_self."' method='post'>    <p><label for='name'>نام:</label> <span class='required'>*</span></p>    <input type='text' ".$error_name." name='name' value='".$name."'>    <p><lable for='email'>پست الکترونیک:</label> <span class='required'>*</span></p>    <input type='text' ".$error_email." name='email' value='".$email."'>  	<p><label for='subject'>موضوع:</label> <span class='required'>*</span></p>    <input type='text' ".$error_subject." name='subject' value='".$subject."'>    <p><label for='body'>پیام شما:</label> <span class='required'>*</span></p>    <textarea ".$error_body." id='body' name='body' style='width:460px;height:119px;'>".$body."</textarea>    <p><label>جمع دوعدد:".$verif."?</label> <span class='required'>*</span></p>              <input type='text' ".$error_captcha."  id='captcha' name='captcha' value=''><br/>     <input type='submit' value='ارسال'/>    </form>";}?>

my web is a persian website with farsi language..

Which part of this code is wrong, do not send an email?

please help me,very very important Because my website on the internet :o:Shock:

Link to comment
Share on other sites

do you have a mail server setup on your host? how are you confirming that the connection was made? you should check the return value of mail instead of just setting a variable to the number 1. this will at least confirm if the mail function executed correctly, so you can further investigate in the right direction.

$mail_sent = mail($address, $subject, $email_content, $headers); if($mail_sent){  //so far so good, at least mail() works}else{  //error sending mail}

if $mail_sent is true, but you still don't get mail, then it's either a mail server issue (contact your host), or possibly your mail is getting sent to a spam folder (check your junk/spam folder).

Edited by thescientist
Link to comment
Share on other sites

I tested your script and here is what I found:

-You need to use session_start() if you are going to use sessions. That is why $captcha != $_SESSION['captcha'] will always fail.

 

-About the captcha, did you mean to add the two numbers and enter the result on the text box, or just concatenate them? Because as it is right now, if you add them, lets say you get 24 + 10 and you enter 34 it will not work. As it is right now, for that example you should write 2410.

 

Here is the complete code that worked for me

<?phpsession_start(); #was missingini_set("display_errors",1); #remove this on production, needed it to see any errors$php_self = $_SERVER['PHP_SELF'];//$error_name = " you don't enter name.please enter you name.";// on submit$mail_sent=0;$error_name = $error_email = $error_subject=$error_body = $error_captcha = '';if( isset($_POST['name']) && isset($_POST['email'])&&isset($_POST['subject']) && isset($_POST['body']) && isset($_POST['captcha']) ){    $name = $_POST['name'];    $email = $_POST['email'];	$subject = $_POST['subject'];    $body = $_POST['body'];    $captcha = $_POST['captcha'];           $error = 0;    // name    if( $name == "" ){ $error=1; $error_name = "class='error'"; }    // email    if( $email == "" ){ $error=2; $error_email = "class='error'"; } 	// subject    if( $subject == "" ){ $error=3; $error_subject = "class='error'"; }    // body    if( $body == "" ){ $error=4; $error_body = "class='error'"; }    // captcha    if( $captcha == "" || $captcha != $_SESSION['captcha']){ $error=5; $error_captcha = "class='error'"; }       // no error, send email    if( $error == 0){                                                // your email address        $address = "info@keivanstone.ir";                   // email subject        $subject = "New body";        // email content        $content = "نام:$nameپست الکترونیک:پیام شما:$email$body";        // html email        $email_content = "<!doctype html><head><meta charset='utf-8'><title>".$subject."</title>";        $email_content .= "</head><body>";        $email_content .= $content;        $email_content .= "</body></html>";                                              // headers for html email        $headers  = 'MIME-Version: 1.0' . "/r/n";        $headers .= 'Content-type: text/html; charset=utf-8' . "/r/n";        $headers .= "From: info@keivanstone.ir" . "/r/n";        // send email        mail($address, $subject, $email_content, $headers);                          // reset variables        $name = ""; $email = ""; $body = "";        $mail_sent = 1;                                                               }}else{    $name = $email = $subject= $body = $captcha = ''; }// captcha$num = rand(1, 40);$num2 = rand(5, 25);   $verif = $num . "+" . $num2;$_SESSION['captcha'] = $num . $num2;       if( $mail_sent == 1 ){    echo "<h1>از تماس شما سپاسگزاریم.تا48 ساعت آینده پاسخ خود را دریافت خواهید کرد.<br/>گروه سنگ آنتیک کیوان</h1>";} else {    echo "    <form action='".$php_self."' method='post'>    <p><label for='name'>نام:</label> <span class='required'>*</span></p>    <input type='text' ".$error_name." name='name' value='".$name."'>    <p><lable for='email'>پست الکترونیک:</label> <span class='required'>*</span></p>    <input type='text' ".$error_email." name='email' value='".$email."'>  	<p><label for='subject'>موضوع:</label> <span class='required'>*</span></p>    <input type='text' ".$error_subject." name='subject' value='".$subject."'>    <p><label for='body'>پیام شما:</label> <span class='required'>*</span></p>    <textarea ".$error_body." id='body' name='body' style='width:460px;height:119px;'>".$body."</textarea>    <p><label>جمع دوعدد:".$verif."?</label> <span class='required'>*</span></p>              <input type='text' ".$error_captcha."  id='captcha' name='captcha' value=''><br/>     <input type='submit' value='ارسال'/>    </form>";}?>
Edited by Lulzim
Link to comment
Share on other sites

hello, i write session_start() above html tags ,this code is a compelate code my contact page(under code)

<?phpsession_start();ob_start();error_reporting(-1);require_once 'config.php';require_once 'header.php';require_once 'db.php';require_once 'category.php';?><!DOCTYPE html><html><head><meta charset="utf8"/><title>گروه سنگ آنتیک کیوان</title><link rel="stylesheet" href="formstyle.css" /></head><body>  <div id="content">	<div id="rightCol">   <div class="sidebar">			<ul>    			<li><span>راهنما</span>					<ul>            			<li><a href="kharid.php">راهنمای خرید</a></li>						<li><a href="pardakht.php">راهنمای پرداخت</a></li>						<li><a href="helpcontact.php">راهنمای تماس باما</a></li>					</ul>				</li>								<li><span>درباره ما</span>					<ul>            			<li><a href="factory.php">درباره کارخانه</a></li>						<li><a href="manager.php">درباره مسئولان</a></li>						</ul>				</li>        				<li>        			<span><a href="contact.php">ارتباط با ما</a></span>				</li>        				<!--<li>        			<span><a href="support.php">پشتیبانی</a></span>            				</li>        				<li><span>واحدفروش</span>					<ul>            			<li><a href="sefaresh.php">سفارش محصول</a></li>						<li><a href="peygiri.php">پیگیری سفارش</a></li>					</ul>				</li>-->			</ul>			</div><!-- sidebar3-->	</div><!--rightCol-->        <div id="leftCol">    	<div class="h1">فرم تماس با ما</div>                    <div class="masir">      <?php echo 'دسته بندی: ' . DisplayPath(5);?>         </div><!--masir-->        <div id="formtamas">      <?php$php_self = $_SERVER['PHP_SELF'];//$error_name = " you don't enter name.please enter you name.";// on submit$mail_sent=0;$error_name = $error_email = $error_subject=$error_body = $error_captcha = '';if( isset($_POST['name']) && isset($_POST['email'])&&isset($_POST['subject']) && isset($_POST['body']) && isset($_POST['captcha']) ){    $name = $_POST['name'];    $email = $_POST['email'];	$subject = $_POST['subject'];    $body = $_POST['body'];    $captcha = $_POST['captcha'];           $error = 0;    // name    if( $name == "" ){ $error ++; $error_name = "class='error'"; }    // email    if( $email == "" ){ $error ++; $error_email = "class='error'"; } 	// subject    if( $subject == "" ){ $error ++; $error_subject = "class='error'"; }    // body    if( $body == "" ){ $error ++; $error_body = "class='error'"; }    // captcha    if( $captcha == "" || $captcha != $_SESSION['captcha']){ $error ++; $error_captcha = "class='error'"; }       // no error, send email    if( $error == 0){                                                // your email address        $address = "info@keivanstone.ir";                   // email subject        $subject = "New body";        // email content        $content = "نام:$nameپست الکترونیک:پیام شما:$email$body";        // html email        $email_content = "<!doctype html><head><meta charset='utf-8'><title>".$subject."</title>";        $email_content .= "</head><body>";        $email_content .= $content;        $email_content .= "</body></html>";                                              // headers for html email        $headers  = 'MIME-Version: 1.0' . "/r/n";        $headers .= 'Content-type: text/html; charset=utf-8' . "/r/n";        $headers .= "From: info@keivanstone.ir <>" . "/r/n";        // send email        mail($address, $subject, $email_content, $headers);                          // reset variables        $name = ""; $email = ""; $body = "";        $mail_sent = 1;                                                               }}else{    $name = $email = $subject= $body = $captcha = ''; }// captcha$num = rand(1, 40);$num2 = rand(5, 25);   $verif = $num . "+" . $num2;$_SESSION['captcha'] = $num . $num2;       if( $mail_sent == 1 ){    echo "<h1>از تماس شما سپاسگزاریم.تا48 ساعت آینده پاسخ خود را دریافت خواهید کرد.<br/>گروه سنگ آنتیک کیوان</h1>";} else {    echo "    <form action='".$php_self."' method='post'>    <p><label for='name'>نام:</label> <span class='required'>*</span></p>    <input type='text' ".$error_name." name='name' value='".$name."'>    <p><lable for='email'>پست الکترونیک:</label> <span class='required'>*</span></p>    <input type='text' ".$error_email." name='email' value='".$email."'>  	<p><label for='subject'>موضوع:</label> <span class='required'>*</span></p>    <input type='text' ".$error_subject." name='subject' value='".$subject."'>    <p><label for='body'>پیام شما:</label> <span class='required'>*</span></p>    <textarea ".$error_body." id='body' name='body' style='width:460px;height:119px;'>".$body."</textarea>    <p><label>جمع دوعدد:".$verif."?</label> <span class='required'>*</span></p>              <input type='text' ".$error_captcha."  id='captcha' name='captcha' value=''><br/>     <input type='submit' value='ارسال'/>    </form>";}?> <div id="payam">      <div><span>منتظر تماس شما هستیم.</span>  <ul>  <li><span>1-ارتباط مستقیم با مدیران کیوان</span></li>  <li><span>2-کسب اطلاعات درباره محصولات ما</span></li>  <li><span>3-نظرات سازنده شما</span></li>  <li><span>4-انتقادات وشکایات شما</span></li>  <li><span>5-و.....</span></li>  <li><span>همه و همه از طریق این صفحه</span></li>  </ul>   <span id="keivan">باتشکر<br/>گروه سنگ آنتیک کیوان</span>    </div> 		</div><!--payam-->  </div><!--formtamas-->    </div><!--leftCol-->           <div class="clr"></div>  </div><!--end of content-->     <div id="footer">حقوق این وبگاه متعلق به گروه سنگ آنتیک کیوان می باشد.</div>  </body></html><?phpob_end_flush();?>

I should make it into php tag I added it to work?And send email?or no i do else things?

please help me...

Edited by sonita
Link to comment
Share on other sites

it doesn't look like you are doing any debugging at all. Aside from the advice I already gave you about checking mail(), how are you tracing your code? You should use echo statements and var_dump to see what the values of variables are, and to see how far you code is making it. That will help you find out what the code is doing, and seeing if it makes it to mail() with all the correct data.

 

it would also be a good idea to add error reporting

 

ini_set('display_errors', 'on');
Link to comment
Share on other sites

Yeah, try to look at error_log if you don't set display errors as thescientist suggested.

 

Here are a few errors you have:

Notice: Undefined variable: nameپست in ...

Meaning if you are going to put a variable inside a string, concatenate it or enclose on {}Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in ...

The email you typed "info@keivanstone.ir <>" is not a vaild email. Remove <> or format it properly.

 

Also, change this line $_SESSION['captcha'] = $num . $num2; to $_SESSION['captcha'] = $num+$num2; because it is very confusing.

 

Look at the code I posted above, I have fixed all these errors :S

Link to comment
Share on other sites

i replace my code with above code you says but showing error,what's mening this errors.

 

Notice: Undefined variable: nameپست in contact.php on line 102

myline 102 is :" $content = "نام:$nameپست الکترونیک:$emailپیام شما:$body";"

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in contact.php on line 114

my line 114 is:[ mail($address, $subject, $email_content, $headers); ]

please help me again.

thanks alot

Link to comment
Share on other sites

The first error means it doesn't know what you're doing with this line:

 

 

$content = "نام:$nameپست الکترونیک:$emailپیام شما:$body";

 

 

It thinks the name of the variable is nameپست

 

You need to tell it specifically what the variables are, you do that by surrounding them with brackets:

 

$content = "نام:{$name}پست الکترونیک:{$email}پیام شما:{$body}";

 

The second error should be obvious - it says it can't connect to a SMTP mail server on the web server. So, it sounds like your web server does not have a mail server running on it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...