Jump to content

[SOLVED] Upgraded to php5 and now mail() not working


nutt318

Recommended Posts

So I have hosting with godaddy and I updgraded my php4 to php5 due to a joomla extension needing php5.

 

Anyways after upgrading some of my other sites mail() sending is no longer working. It acts like it sends the mail but I never receive the message.

 

I'm guessing some properties changed on how the mail() function works but have been searching forums and google and havent found anything. I have been playing around with it and its something to do with the message part. It not showing the varibles properly and cant find any examples.

 

$msg = "Name:                     $name \n";
$msg = "E-Mail Address:        $email \n";
$msg = " \n";
$msg = "$message \n";

$headers = "From: $name<$email>";

echo'
<HTML><HEAD><TITLE>' . $waitmessage . '</TITLE>
<META HTTP-EQUIV="refresh" CONTENT="3;url=' . $redirecturl . '">';
mail ($ToEmail, $subject, $msg, $headers);

 

Thanks for the help, if possible can someone provide an example on how to make this work?

Link to comment
Share on other sites

It's not a mail() problem (nothing changed between php4 and php5) and it is not a php5 problem either.

 

Your code was relying on the lazy-way register_globals to "magically" populate program variables from your form data. Register_globals were turned off by default in php4.2 in the year 2002 because they also magically allowed hackers to set session variables by simply putting a same name parameter on the end of the URL.

 

You need to add code to set the variables $name, $email, $message, and any other ones that come from your form, using the correct $_POST['name'], $_POST['email'] ... variables.

 

Link to comment
Share on other sites

Ok, here is the entire code I'm using, I am setting the variables unless this is the wrong way of doing it.

 


                                                                <?PHP
# Only edit the following lines
$redirecturl="http://www.mysite.com";	 	# Where you're sent after submitting the contact form
$subject="mysite - Customer Question"; 				# Subject of the email message
$waitmessage="Please Wait.  Sending Information.  You will now be redirected back to the homepage.";	# Message shown to user while emailing their info
$ToEmail="support@mysite.com";				# Enter email address in between


$name = $HTTP_POST_VARS['userName'];
$email = $HTTP_POST_VARS['userEmail'];
# $phone = $HTTP_POST_VARS['userPhone'];
# $subject2 = $HTTP_POST_VARS['userSubject'];
$message = $HTTP_POST_VARS['userMessage'];

# if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
#  echo "<h4>Invalid Email Address</h4>";
#  echo "<a href='javascript:history.back(1);'>Back</a>";


$msg = "Name:                     $name \n";
$msg = "E-Mail Address:        $email \n";
$msg = " \n";
$msg = "$message \n";

$headers = "From: $name<$email>";

echo'
<HTML><HEAD><TITLE>' . $waitmessage . '</TITLE>
<META HTTP-EQUIV="refresh" CONTENT="3;url=' . $redirecturl . '">';
mail ($ToEmail, $subject, $msg, $headers);
echo '
<CENTER>' . $waitmessage . '
<P>
</P>
';




?>

Link to comment
Share on other sites

  • 4 years later...

Thank you PFMaBiSmAd and nutt318! This post helped me out! Below is my code with the form vars declared as php vars:

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "totallytotallyamazing@gmail.com";
    $email_subject = "TTA FILL-IN FORM";

 

// DECLARE FORM VARS AS PHP VARS   
    $name = $_POST['name'];
    $email = $_POST['email'];
    $url = $_POST['url'];
    $comment = $_POST['comment'];

    
    $email_message .= "Name: ".($name)."\n";
    $email_message .= "Email: ".($email)."\n";
    $email_message .= "URL: ".($url)."\n";
    $email_message .= "Comments: ".($comment)."\n";
    
// create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);

}
?>

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.