Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to get SMTP to work in a contact form i am using to send info to an email. Here is the HTML for it. When i hit the submit button it just goes to the newsendform.php page which is just blank. Anyone have any ideas?

<form action="newsendform.php"  method="POST">
					<legend>Request a FREE Quote Now!</legend>
										<div class="inputs">
						<input type="text" id="inp_name" name="name" required placeholder="Name *" style="
    width: 90%;">
						<input type="text" id="inp_phone" name="number" required placeholder="Phone*" style="
    width: 90%;">
						<input type="text" id="inp_cmail" name="email" required placeholder="Email*" style="
    width: 90%;">						
					        <textarea name="comments" id="input_1_5" class="textareasmall" tabindex="6" rows="10" cols="50" placeholder="Message" style="
    width: 90%;    padding-left: 5px;    border-radius: 4px;    
    height: 105px;    
    margin: 2px 25px 2px 0;    border: none;    font-size: 16px;    line-height: 1.3;
					<div class="submit_button"><input type="submit" name="btnSubmit" value="Request My Quote"></div>

The PHP is as follows:

$mail = new PHPMailer();

//Your SMTP servers details

$mail->IsSMTP();               // set mailer to use SMTP
$mail->Host = "";  // specify main and backup server or localhost
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "";  // SMTP username
$mail->Password = "11111"; // SMTP password
$mail->Port = 80;  

$redirect_url = "thankyou.php"; //Redirect URL after submit the form

$mail->From = $mail->Username;  //Default From email same as smtp user
$mail->FromName = "Drywall Pros";

$mail->AddAddress("", "Myname"); //Email address where you wish to receive/collect those emails.

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = $_POST['email'];
$message = "Name :".$_POST['name']." \r\n <br>Email Adrress :".$_POST['email']." \r\n <br> Phone number :".$_POST['number']."\r\n <br> Message: ".$_POST['comments']."\r\n <br> ;
$mail->Body    = $message;

   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;

echo "Message has been sent";
header("Location: $redirect_url");

1 solution

The answer would be almost the same as my recent answer: Contact Form not sending senders email address[^].

In your case, you need to checkup your data and debug the code. You need to check up all the data which come through $_POST by debugging or any kind of service logging. I'm not sure that first isset condition evaluates to true; probably not; it would explain the rest. Why are you doing this test? You can use any other form field. Why do you think that the name of the submit button is passed through HTTP request? it would not make any sense.

Also, check up all the SMTP setting. Make sure that the message is passed through SMTP if you use some available mail client with the same options and authentication data.

Share this answer
Member 11661173 4-May-15 16:19pm    
Is there any need to even have the isset condition ?
Sergey Alexandrovich Kryukov 4-May-15 16:33pm    
It might be. Here is the deal: I don't know what is "newsendform.php". It could be the same file as the one with the form. In this case, you would need to differ two cases: 1) when you got to this page as a result of form submit; then you need to take into account post data; 2) other cases.

You can consider other methods, such as checking 'HTTP_REFERE' in Hope you don't have other links on the page pointing to itself. :-)

Member 11661173 4-May-15 16:50pm    
I see. No it isnt the same file as the one with the form.
I don't know if you could but if you do have time , take a look at this person's example.

Is there anything to do in there other than change the field names and the smtp configuration file to match my own. Does the form action field have to be empty as it is in the example?
Sergey Alexandrovich Kryukov 4-May-15 17:29pm    
Then you don't need even to test anything. I guess, the file which is action attribute value of your form, is not referenced in any other way from your side, because it would not make any sense. Is that right?

So, you still may need some test, but only to filter our the situation when some "too smart" user directly type "*/newsendform.php" in the address bar, something which makes no sense. The you could expect that $_POST['name'], $_POST['email'], ".$_POST['number'], and $_POST['comments'] are not set (or null, or empty, doesn't matter). You can check it up, to show some kind of "get way" message or just show an empty page (why not?); something like that.

Member 11661173 4-May-15 18:40pm    
Since he includes the include('SMTPconfig.php');

files in the index.php im guessing there is no reason to put in form action="url" ? Is that what you meant?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900