Jump to content

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="joshua.ward@me.com" 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

 

Edited by joshwah
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.

Edited by jazzman1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.