-2

Can anybody help me! This php doesn't work in my web, doesn't send email, if i change die(error), the page say to me that.. enter image description here

There is de php action

    <?php
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['mail'];
$Title = $_POST ['position/title'];
$company = $_POST ['company'];
$location = $_POST ['location'];
$telephone = $_POST['telephone'];
$services = $_POST['services'];
$string = join(" \r\n ", $services);
$timeframe = $_POST['timeframe'];
$comments = $_POST['comments'];
$learn = $_POST['learn'];
        $message = '<html><body>';
        $message .= '<img src="http://www.corbisglobal.com/assets/web/img/contact-CG-logo.png" />';
        $message .= '<table rules="all" style="border-color: #666; border : 1px;" cellpadding="10">';
        $message .= "<tr style='background: #ddd;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) .  "</td></tr>";
         $message .= "<tr style='background: #eee;'><td><strong>Lastname:</strong> </td><td>" . strip_tags($_POST['lastname']) . "</td></tr>";
        $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['mail']) . "</td></tr>";
         $message .= "<tr><td><strong>Title/Position:</strong> </td><td>" . strip_tags($_POST['position/title']) . "</td></tr>";
        $message .= "<tr><td><strong>Company:</strong> </td><td>" . strip_tags($_POST['company']) . "</td></tr>";
        $message .= "<tr><td><strong>Location:</strong> </td><td>" . strip_tags($_POST['location']) . "</td></tr>";
         $message .= "<tr><td><strong>Services:</strong> </td><td>" . join(" \r\n, ", $services) . "</td></tr>";
         $message .= "<tr><td><strong>Timeframe:</strong> </td><td>" . strip_tags($_POST['timeframe']) . "</td></tr>";
         $message .= "<tr><td><strong>Learn about Corbis:</strong> </td><td>" . strip_tags($_POST['learn']) . "</td></tr>";
        $message .= "<tr><td><strong>Comments:</strong> </td><td>" . strip_tags($_POST['comments']) . "</td></tr>";
        $message .= "</table>";
        $message .= "</body></html>";
$recipient = "recipient@example.com";
$subject = "Contact Form from CorbisGlobal Web";
$mailheader .= "MIME-Version: 1.0\r\n";
$mailheader .= "From: " . strip_tags($_POST['mail']) . "\r\n";
$mailheader .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($recipient, $subject, $message, $mailheader) or die (error);
header("Location: thankyou.php"); 
exit; 
?>
scrappedcola
  • 10,021
  • 1
  • 28
  • 41
  • 4
    A 500 error = Server error (probably some PHP error). Check your error log or turn display errors on and you will get a proper error message you can share with us. Here you can see how to turn it on: http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Magnus Eriksson Sep 26 '16 at 18:39
  • 3
    Btw, why are you storing all the post values in variables, and then use the post variable directly anyway, later on? – Magnus Eriksson Sep 26 '16 at 18:41

1 Answers1

4

Your error is probably on the middle row:

$subject = "Contact Form from CorbisGlobal Web";
$mailheader .= "MIME-Version: 1.0\r\n";
$mailheader .= "From: " . strip_tags($_POST['mail']) . "\r\n";

You didn't create the variable $mailheader before you're adding more text to it.

Turn error reporting on and you'll have meaningful error messages that will help you solve most of your problems.

Also, you're doing this:

mail($recipient, $subject, $message, $mailheader) or die (error);

or die (error), you probably didn't define the error constant, and there is no variable with this name in the code you have shown us. To check if the mail function has accepted your input, you can do this:

if (mail($recipient, $subject, $message, $mailheader)){
    header("Location: thankyou.php"); 
}
else{
    die("Error sending email");
}
Phiter
  • 12,987
  • 14
  • 45
  • 77
  • Yes, this is probably it (assuming the OP didn't omit this) – The One and Only ChemistryBlob Sep 26 '16 at 18:43
  • I seriously doubt that would lead to a http 500 error. – jeroen Sep 26 '16 at 18:44
  • There is also a problem with his "or die" function, I have added it to the answer. – Phiter Sep 26 '16 at 18:49
  • When turn on the errors, appear that: Warning: join(): Invalid arguments passed in /srv/www/corbis-www/mail.php on line 12 Warning: join(): Invalid arguments passed in /srv/www/corbis-www/mail.php on line 30 Error sending email When i delet this line.. Die.. error sending email... – Emiliano Maza Sep 26 '16 at 19:06
  • Don't forget the `exit;` after the `header('location: ...');` (that will probably not fix your error, but you should always have an `exit;` after a redirect-header.) – Magnus Eriksson Sep 26 '16 at 19:09
  • @EmilianoMaza - Does `$_POST['services']` actually contain an array? – Magnus Eriksson Sep 26 '16 at 19:11
  • it's stranger that, if a test in other server the same code, it's works... http://emilianomaza.com.ar/contact-form-corbis/contact.php @MagnusEriksson you mean form code? nop – Emiliano Maza Sep 26 '16 at 19:18
  • 1
    I mean, you're sending `$services` as the second param in your `join()`-call. If that's not an array, you will get the error you just showed. `join()` is an alias for `implode()`.. here's the manual for it: http://php.net/manual/en/function.implode.php – Magnus Eriksson Sep 26 '16 at 19:20