Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Mailer not sending 1

Status
Not open for further replies.

Evil8

MIS
Mar 3, 2006
313
0
0
US
I've got a simple mailer up and everything seems to be working, it validates the fields and gives the thank you message, but no email ever gets sent.

mail.html
Code:
<head>
  <title>Contact Form</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <link rel="stylesheet" type="text/css" href="CSS/style.css">
  <link href=' [URL unfurl="true"]http://fonts.googleaplis.com/css?family=Permanent+Marker'[/URL] rel='stylesheet'>
  <link rel="stylesheet" href="CSS/form.css" type="text/css" media="all">
  <link rel="stylesheet" href="CSS/validationEngine.jquery.css" type="text/css" media="screen" title="no title" charset="utf-8">
  <link rel="stylesheet" href="CSS/template.css" type="text/css" media="screen" title="no title" charset="utf-8">


<script src="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"[/URL] type="text/javascript"></script>

		<script src="js/jquery.validationEngine-en.js" type="text/javascript"></script>
		<script src="js/jquery.validationEngine.js" type="text/javascript"></script>

		<script>
		$(document).ready(function() {
			
			
			
			// SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() }, 
			$("#form1").validationEngine({
				ajaxSubmit: true,
					ajaxSubmitFile: "ajaxSubmit.php",
					ajaxSubmitMessage: "Thank you, We will contact you soon !",
				success :  false,
				failure : function() {}
			})
			

		
		});
		</script>
        
        
</head>

<body>

...some html here...

  <div id="wrapper">

   <h1>Contact Us:</h1>
    <div id="form-div">
    <form class="form" id="form1" method="post" action="ajaxSubmit.php">
      <p class="name">
        <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] text-input" id="name">
        <label for="name">Name</label>
      </p>
      <p class="email">
        <input name="email" type="text" class="validate[required,custom[email]] text-input" id="email">
        <label for="email">E-mail</label>
      </p>
      <p class="text">
        <textarea name="text" class="validate[required,length[6,300]] text-input" id="comment"></textarea>
      </p>
      <p class="submit">
        <input type="submit" value="Send">
      </p>
    </form>

    </div><!-- end form -->
    </div><!--end wrapper-->
</body>
</html>

ajaxSubmit.php
Code:
<?php

$name = $_POST['name']; // contain name of sender
$email = $_POST['email']; // Email address of sender 
$body = $_POST['text']; // Your message 
$receiver = "me@myEmail.com" ; // The email address that all our feedbacks will be sent to 
if (!empty($name) & !empty($email) && !empty($body)) {
    $body = "Name:{$name}\n\nComments:{$body}";
	$send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
    if ($send) {
        echo 'true'; //if everything is ok,always return true , else ajax submission won't work
    }

}

?>


any ideas?
 
Get rid of the curly brackets here:
Code:
Name:{$name}\n\nComments:{$body}

These brackets are likely confusing the IF statement.

There might be other issues but that is what jumped out first.
 
Hi spamjim, that didn't seem to make any difference.

Getting this in the console:

Resource interpreted as Stylesheet but transferred with MIME type text/html: " mail.html:8
error: TypeError: Cannot call method 'compareDocumentPosition' of undefined change_sink.js:218
error: TypeError: Cannot call method 'compareDocumentPosition' of undefined change_sink.js:218
error: TypeError: Cannot call method 'compareDocumentPosition' of undefined change_sink.js:218
error: TypeError: Cannot call method 'compareDocumentPosition' of undefined change_sink.js:218
error: TypeError: Cannot call method 'compareDocumentPosition' of undefined change_sink.js:218
error: TypeError: Cannot call method 'compareDocumentPosition' of undefined change_sink.js:218

Hummm....
 
Fixed that first console error. I'm lost on the other issue(s).
 
The console errors are about skype and the phone numbers listed on the page. Nothing I need to worry about. Still not mailing, but I'm working on it... :)
 
Good morning everyone. I really appreciate everyone's help and input. It seems, as far as I can tell, that the ajax and php should be working, but I'm still not getting the email the contact form should generate. I'm wondering if there is a step somewhere in the php that defines where the mail should be sent from (server?) and how (protocol?)

Again thanks for all your help.
 
Have you made sure the server is properly configured to send mail?

As a simple test build a PHP page that only attempts to send an email, and try to run that. Do you get the email?

Code:
[COLOR=#990000]<?php[/color]
[COLOR=#009900]$sent[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]mail[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]"youremail@server.com"[/color][COLOR=#990000],[/color] [COLOR=#FF0000]'Test Email sending'[/color][COLOR=#990000],[/color] [COLOR=#FF0000]"Is this email being sent"[/color][COLOR=#990000],[/color] [COLOR=#FF0000]"From: {youremail@server.com}"[/color][COLOR=#990000]);[/color]

[b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$sent[/color][COLOR=#990000])[/color] [COLOR=#990000]&&[/color] [COLOR=#009900]$sent[/color][COLOR=#990000]==[/color]true[COLOR=#990000])[/color]
[COLOR=#FF0000]{[/color]
[tab][b][COLOR=#0000FF]echo[/color][/b] [COLOR=#FF0000]"Mail passed on to server for delivery successfully"[/color][COLOR=#990000];[/color]
[COLOR=#FF0000]}[/color]
[b][COLOR=#0000FF]else[/color][/b]
[COLOR=#FF0000]{[/color]
[tab][b][COLOR=#0000FF]echo[/color][/b] [COLOR=#FF0000]"Error Passing mail to server for delivery"[/color][COLOR=#990000];[/color]
[COLOR=#FF0000]}[/color]
[COLOR=#990000]?>[/color]

Also make sure the emails aren't getting trapped by your Spam filter and getting sent to your spam box.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Vacunita your test returns true. So the email is being passes as I suspected, but it doesn't GO anywhere. The website is hosted on inmotion hosting webservers. So there is something there I'm missing.

Thanks.
 
Oh and it isn't getting caught up in the junk mail or spam filter.
 
That means its successfully getting passed on to the mail server. Which means its not a code issue at any level. I would check again the server settings to make sure the server is actually sending mail. It seems to me the outgoing sever is not properly configured, and while PHP can happily hand the email over to the server, the server just sits on it or simply can't deliver it.

If this is a hosted server contact your hosting company, if this is a company server you may want to contact the Administrator. Otherwise, you'll have to look into your settings to find out how its set up.

As a further alternative you may want to look into PHPMailer, it has its own SMTP included so no need to hassle with server settings.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
vacunita,

Okay I think I used this PHPMailer before, but it was so long ago and files have been deleted since then. I uploaded the class.phpmailer.php and the class.smtp.php files to the webserver.

If I was modifying my code to do this would I add the code to my ajaxSubit.php page like this?

Code:
php?

require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

try {
  $mail->Host       = "mail.yourdomain.com"; // SMTP server
  $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
  $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
  $mail->Username   = "yourname@yourdomain"; // SMTP account username
  $mail->Password   = "yourpassword";        // SMTP account password
}

$name = $_POST['name']; // contain name of sender
$email = $_POST['email']; // Email address of sender 
$body = $_POST['text']; // Your message 
$receiver = "me@myEmail.com" ; // The email address that all our feedbacks will be sent to 
if (!empty($name) & !empty($email) && !empty($body)) {
    $body = "Name:{$name}\n\nComments:{$body}";
	$send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
    if ($send) {
        echo 'true'; //if everything is ok,always return true , else ajax submission won't work
    }

}

These try codes?

->Username =
->Password =

Are these the referring to a login and password for an email user such as I would use to setup email on an email client? If so that doesn't look very secure.

Thanks again.
 
IF you are using an external SMTP server that may require credentials to send the email you would need to provide those. The PHP code is not delivered to the client, so those credentials are as secure as your server and by extension the rest of your code is. This would also go hand in hand with your server configuration to prevent massive mailings from that particular account or something similar to prevent unauthorized usage of that particular account.

However since what you want is to avoid using the SMTP server on your host as that is having issues sending email do not call the isMTP function, don't provide any credentials there and simply let PHPMailer send the email itself.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Okay I'm working on my ajaxSubmit.php file

Code:
<?php
 
$name = $_POST['name'];   // contain name of sender
$email = $_POST['email']; // email address of sender 
$body = $_POST['text'];   // the message 

require_once("class.phpmailer.php");
 
$mail = new PHPMailer();
 
$mail->IsSMTP();                              // set mailer to use SMTP
$mail->Host = "mail.mydomain.com";     // specify main and backup server
$mail->SMTPAuth = true;                       // turn on SMTP authentication
$mail->Username = "mailuser@mydomain.com";  // SMTP username
$mail->Password = "********";              // SMTP password
 
$mail->FromName = $name; //name of sender on the contact form
$mail->From = $email;    //email address on the contact form
 
$mail->WordWrap = 50; // set word wrap to 50 characters

$mail->IsHTML(true); // set email format to HTML

$mail->Body    = $text;  // $text is the user's message they typed in
$mail->AltBody = $text;
 
 
$receiver = "me@mydomain.com" ; // the email address the our contact form will be sent to

if (!empty($name) && !empty($email) && !empty($body)) {
    $body = "Name:{$name}\n\nComments:{$body}";
	$send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
    if ($send) {
        echo 'true'; //if everything is ok, always return true, else ajax submission won't work
    }

}
?>

Okay I've got this far and didn't get an error in the console, but still no email.
 
Well never mind. I've found that the original ajaxSubmit.php has been passing the email to a mail box on the webserver. I just need to figure out how to get that email to forward to the end user and that would be a host service issue and not a coding issue.

Thank you everyone for your help. Sorry to be a pain in the ass.

 
It looks like moving an email from the hosted webserver local host email box to my exchange email box isn't going to happen so I'm back to working on a PHPMailer solution.
 
This issue has been solved! I am using the original (fixed) ajaxSubmit.php with a send to email address at our exchange server. As we determined that the info was sending, it was only a matter of where, I changed the mx listing on the hosted web server (inmotion hosting control panel) to our actual mx record with priority 0.

Again thank you for all your time and help. I do appreciate it.

Evil8

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top