Jump to content

PHP Emailer Problem


sheldongold

Recommended Posts

Hi all!!

It's been a while since I was last needing some PHP help, but I knew the time would come!!  I have tried to add an online emailer to a site.  I am sure that I've used this code before without any problems but it's not working.  I have uploaded it to the webspace and am able to get all the way through and the mailer reports that the email has been sent.  However, it never gets received...

When I send something through mail($to, $subject, etc.... where is it sending it to exactly??  Do I not need to specify the pop or smtp settings or anything like that??  I get no error messages to work from so I'm pretty stuck.

Here is my code if it is of any use in aiding me.  Any help is super greatly appreciated!!

Many thanks
Sheldon

[code]<?php
// set flag to indicate whether mail has been sent
$mailSent = false;
if (array_key_exists('ewComments', $_POST)) {
// mail processing script
// remove escape characters from POST array
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value) {
    $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
    return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
}
//validate the input, beginning with name
$name = trim($_POST['name']);
if (empty($name)) {
$error['name'] = 'Please enter your name';
}
$email = $_POST['email'];
// check for valid email address
$pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
if (!preg_match($pattern, trim($email))) {
$error['email'] = 'Please enter a valid email address';
}
// check the content of the message area
$messageBody = trim($_POST['message']);
if (empty($messageBody)) {
$error['message'] = 'Please enter your message';
}
// initialise variables
$to = 'sheldongold@invate.co.uk';
$subject = 'Comment from Invate website';

// build the message
$message = 'On '.date('l, M j, Y').' at '.date('g:ia').', ';
$message .= "$name ($email) wrote: \n\n";
$message .= $messageBody;

// build the additional headers
$additionalHeaders = "From: Invate Website<info@invate.co.uk>\n\n";
$additionalHeaders .= "Reply-To: $email";

// send the email if there are no errors
if (!isset($error)) {
$mailSent = mail($to, $subject, $message, $additionalHeaders);
// check that the mail was sent successfully
if (!$mailSent) {
$error['notSent'] = 'Sorry, there was a problem sending your mail.  Please try again later.';
}
}
}
?>
<div id="main_nav">
  <table cellpadding="0" cellspacing="0" id="tbl_main">
    <tr>
      <td id="td_main_side"><img src="images/footer_filler.gif" alt="main filler" width="20" height="39" /></td>
      <td id="td_main_content"><?php if (isset($error['notSent'])) { ?>
    <h1>Server Error </h1>
    <p class="warning"><?php echo $error['notSent']; ?></p>
<?php } elseif ($mailSent) { ?>
<h1>Thank you for your comments</h1>
<p>We appreciate your feedback, and will be in touch if neccessary.</p>
<?php } else { ?>
    <h1>Send us your comments </h1>
    <p>We hope you have enjoyed the site. If you have any comments or questions or simply want to contact us, please fill in the following form. Invate will not use your name or email address for any purpose other than replying to you. </p>
<?php } ?>
    <?php if (!$mailSent) { ?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="contactForm" id="contactForm" onsubmit="MM_validateForm('name','','R','email','','RisEmail','message','','R');return document.MM_returnValue">
        <p>
          <label for="name">Name:</label> <?php if (isset($error['name'])) { ?>
  <span class="warning"><?php echo $error['name']; ?></span>
  <?php } ?>
          <br />
          <input type="text" name="name" id="name"
  <?php if(isset($error)) {echo "value='$name'";} ?> />
      </p>
        <p>
          <label for="email">Email:</label> <?php if (isset($error['email'])) { ?>
  <span class="warning"><?php echo $error['email']; ?></span>
  <?php } ?>
  <br />
          <input type="text" name="email" id="email"
  <?php if(isset($error)) {echo "value='$email'";} ?> />
        </p>
        <p>
          <label for="message">Message:</label> <?php if (isset($error['message'])) { ?>
  <span class="warning"><?php echo $error['message']; ?></span>
  <?php } ?>
  <br />
          <textarea name="message" id="message"><?php if(isset($error)) {echo $messageBody;} ?></textarea>
        </p>
        <p>
          <input name="ewComments" type="submit" id="ewComments" value="Send Message" />
        </p>
    </form>
<?php } ?>
      </td>
    </tr>
  </table>
</div>

[/code]

THANKS AGAIN IN ADVANCE!!!

Link to comment
Share on other sites

I have had a response from another forum from someone that has taken my script, changed the email address to his own and uploaded it to his server.  And it works perfectly.  Where could the problem be lying?  Is my mail somehow being reported as spam or something and not being sent out or is there a problem with my Fasthosts server?

Once again dudes, any help is greatly appreciated!

Sheldon
Link to comment
Share on other sites

I've created a new php file and uploaded it.  This is the content:

<?php
mail("myemailaddress@here", "test", "test", "From: noOne");
?>

I have run this from the online server and get no email returned to me.  So the problem must lie with the hosts yes?  Has anyone else had any problems with Fasthosts?  I have read that if the NOBODY account is set to off that this sort of problem can occur.  Is this correct?
Link to comment
Share on other sites

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.