Jump to content

Send-Mail.php Shows Errors


joshwah

Recommended Posts

I have a contact form that uses send-mail.php. I got it to work on one site and literally copied it to another site but it doesn't work. The error shows and the success message shows and it certainly doesn't send emails.

 

 

-----------------------------------------------------------------

PHP Code

-----------------------------------------------------------------

 

<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
 
$from = $_POST['email'];
 
//data
$msg = "NAME: "  .$_POST['name']    ."<br>\n";
$msg .= "EMAIL: "  .$_POST['email']    ."<br>\n";
$msg .= "COMMENTS: "  .$_POST['comments']    ."<br>\n";
 
//Headers
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
 
 
//send for each mail
foreach($to as $mail){
   mail($mail, $subject, $msg, $headers);
}
 
?>

 

-----------------------------------------------------------------

Form Code
-----------------------------------------------------------------

 

<!-- form -->
<script type="text/javascript" src="_/js/form-validation.js"></script>
<form id="contactForm" action="#" method="post">
<fieldset>
<p><input name="name" id="name" type="text" class="text" placeholder="Full Name" title="Enter your full name" /></p>
 
<p><input name="email" id="email" type="text" class="text" placeholder="Email Address" title="Enter your email address" /></p>
 
<p><textarea name="comments" id="comments" rows="5" cols="38" placeholder="Message" title="Enter your comments"></textarea></p>
 
<!-- send mail configuration -->
<input type="hidden" value="[email protected]" name="to" id="to" />
<input type="hidden" value="Sioux Signs Inquiry" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
 
<p><input type="button" value="Submit" name="submit" id="submit" class="submit" /> <span id="error" class="warning">Something went wrong. Please refresh your page and try again.</span></p>
</fieldset>
</form>
<p id="sent-form-msg" class="success">Your message has been sent. We'll be in touch soon.</p>
                </div> <!-- ENDS form -->
 

-----------------------------------------------------------------

 

This same form works on another site. I'm not sure why. Any suggestions? 

 

post-146664-0-87425900-1365748245_thumb.jpg

 

Link to comment
https://forums.phpfreaks.com/topic/276857-send-mailphp-shows-errors/
Share on other sites

Most of the hosting providers did not allow the users to send mail through their servers... Contact the server administration of the query....

 

bullshit-meter-01_thumb.gif

 

 

@OP, this is wrong:

$msg = "NAME: "  .$_POST['name']    ."<br>\n";
$msg .= "EMAIL: "  .$_POST['email']    ."<br>\n";
$msg .= "COMMENTS: "  .$_POST['comments']    ."<br>\n";

Correct one for Unix platform:

 
$msg = "NAME: " .$_POST['name'] ."\n";
$msg .= "EMAIL: " .$_POST['email'] ."\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."\n";
 

For non-Unix platform:

 
$msg = "NAME: " .$_POST['name'] ."\r\n";
$msg .= "EMAIL: " .$_POST['email'] ."\r\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."\r\n";
 

You can also check - PHP_EOL.

 

EDIT: Never ever loop the mail function.

 

Take a look at this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.