Jump to content

PHP Mail function!


jester275

Recommended Posts

Hey guys,

 

Got a quick question for you. I am using the php mail function with an xhtml form to allow prospective customers to submit enquiries. The form is embedded on a page called contact.html and looks like this:

<form method="POST" action="emailsubmit.php" onsubmit="return check(this);">

<table>

<tr>

<td>Name:</td><td><input type="text" name="name" size="30"></td>

</tr>

<tr>

<td>Your Email address:</td><td><input type="text" name="email" size="30"></td>

</tr>

<tr>

<td>Your Query/Comment:</td><td><textarea rows="8" name="message" cols="70"></textarea></td>

</tr>

<tr></tr>

<td></td><td><input type="submit" value="Send Email!" name="submit"></td>

</table>

</form>

 

This points to a php script on a page called emailsubmit.php. The code on this page looks like this:

 

<?php

//**If submit is set then send mail to [email protected] and print thanks for submitting email message**//

if(isset($_POST['submit'])) {

 

$to = '[email protected]';

$subject = 'TM Akers Enquiry';

$name = $_POST['name'];

$email = $_POST['email'];

$message = $_POST['message'];

//**Body is made up of the name specified in the name text box, the senders manually enetered email address and their message**//

$body = "From: $name\n E-Mail: $email\n Message:\n $message";

echo '<br />';

echo '<br />';

echo 'Thanks for submitting your email. Tim will get back to you as soon as possible.';

mail($to, $subject, $body);

echo '<br />';

echo '<br />';

echo '<br />';

 

}

 

else {

 

echo "For some reason your email attempt failed! Please try again later.";

 

}

?>

 

 

Despite my best efforts, the form submits but does not send the email. The first echoed message appears when submitted, but is then followed by the second echoed message once a user clicks on contact.html again. I have no idea why! I have had this script running on a different server, and it has worked a treat! Any clues?

 

Many Thanks,

 

James

Link to comment
https://forums.phpfreaks.com/topic/120584-php-mail-function/
Share on other sites

Hey!

 

Thanks for getting back to me. I tried adding a from header earlier and just tried it again then. Sadly, no joy!

 

Any other ideas? Do you think it could be something with the hosting I have just switched to? They have php 5 running on a linux server

 

Cheers, James

Link to comment
https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621394
Share on other sites

I don't understand what you mean when you say

 

"The first echoed message appears when submitted, but is then followed by the second echoed message once a user clicks on contact.html again."

 

Which error do they get, "For some reason your email attempt failed! Please try again later."?

 

If so, that should not appear unless they go right to emailsubmit.php without going to contact.html first.

Link to comment
https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621452
Share on other sites

Sorry for not being clear....

 

 

When the form is submitted a message is echoed informing a user that their message has been recieved. As you can see, this is done in the same if statement that send s the message. Below this if statement is an else statement that prints:

 

"For some reason your email attempt failed! Please try again later. Alternatively send us an email to <a href='mailto:[email protected]'>[email protected]</a>"

 

Currently, when a form is submitted on the site, the first statement is printed (Thanks for submitting your email. x will get back to you as soon as possible). However, if a user attempts to click on contact.html again, the else statement randomly prints. If you want to see it, the site is at www.timakersantiques.com/contact.html

 

Cheers once again, James

Link to comment
https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621456
Share on other sites

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.