PHP crisis

Good Afternoon,

I wonder if somebody can help me with a PHP crisis I’m having.

I am using a html template I purchased to create a contact form using PHP. The original template used validation and “sendmail function” which only works once and then I have to wait about 30 minutes otherwise I recieve a 500 Internal Server error. I contacted my hosting provider (mellow host) and they informed me that the script I am using would not work as their systems will only work with SMTP authentication within the PHP script. I am left wondering why it works but then I have to wait for 30 minutes???

Here is the original PHP script: www.gainfordstevens.co.uk/bin/process.php

Can anybody advise why it’s not functiong correctly and whether it’s possible to be adapted for SMTP authentication?

I have created my own form which I have done on a number of occasions for myself and other people however I am having a similar issue. It works a few times and then I get a 500 Internal server error.

Here is my page: www.gainfordstevens.co.uk/contact
Here is the PHP file: www.gainfordstevens.co.uk/contact/contact.php
Here is my ASP authentication file: www.gainfordstevens.co.uk/contact.asp

Why am I having these issues, is it me or my hosting provider?

Thank-in-adance, any help appreciated.

Thanks
Liam

You can try sending emails via SMTP. Here is a function that you can use in your code (just replace host, port, username, password):
[php]<?php

// Sending emails via SMTP ***********************************************

function mail_smtp ($to, $subject, $mess, $hdrs=""){

require_once "Mail.php";

$host     = "ssl://smtp.gmail.com";
$port     = "465";
$username = "[email protected]";
$password = "12345";

$headers = array (
 'To' => $to,
 'Subject' => $subject,
 'MIME-Version' => '1.0',
 'Content-type' => 'text/html; charset=utf-8',
 'Content-transfer-encoding' => '8Bit');

if($hdrs!=''){
  $arr=explode("\n",trim($hdrs));
  if($arr) foreach($arr as $line){
    $arrnew=explode(": ",trim($line));
    $headers[trim($arr[0])]=trim($arrnew[1]);
  }
}

$smtp = Mail::factory('smtp',
  array ('host' => $host,
   'port' => $port,
   'auth' => true,
   'username' => $username,
   'password' => $password));

$mail = $smtp->send($to, $headers, $mess);

if(PEAR::isError($mail)){
  return false;
}
else{
  return true;
}

}

?>
[/php]

As you can see this function have the same arguments as standard mail() function, so you just need to search in your code mail( and replace it with smtp_mail( .
Note, this function requires PEAR Mail module installed. If your hosting provider have no this module, you can try class PHPMailer.

Thank You very much for your prompt reply!

I don’t want to sound stupid but I’m only a Junior Web Designer with very basic PHP knowledge.

Do I just paste that into my current PHP script? Would you like me to post my current script?

Thanks-in-advance.

Liam

[code]<?php
// Chnage this according to your settings

$to = ‘[email protected]’; // Change the mail according to your need.
$subject = “Contact Form”; // Mail Subject
$success_msg = ‘Your Message has been submitted and we will get back to you ASAP.

’; // The message displayed after successful mail delivery
$failure_msg = ‘

Contact Form Submitted!

Due to some reason mail is not sent.

’; // The message displayed after mail delivery failure

//Do not edit below this line.

if ( trim($_POST[‘names’]) != ‘’ ) {
$names = stripslashes(strip_tags($_POST[‘names’]));
} else {
$names = ‘No name entered’;
}
if ( trim($_POST[‘emails’]) != ‘’ ) {
$emails = stripslashes(strip_tags($_POST[‘emails’]));
} else {
$emails = ‘No email entered’;
}
if ( trim($_POST[‘phone’]) != ‘’ ) {
$phone = stripslashes(strip_tags($_POST[‘phone’]));
} else {
$phone = ‘No phone number entered’;
}
if ( trim($_POST[‘comments’]) != ‘’ ) {
$comments = nl2br(stripslashes(strip_tags($_POST[‘comments’])));
} else {
$comments = ‘No comments entered’;
}
ob_start();
?>

.style3 {color: #000000}
Name <?=$names;?>
Email <?=$emails;?>
Comments <?=$comments;?>
<? $body = ob_get_contents(); ob_end_clean();

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= ‘From: ‘.$names.’ <’.$emails.’>’ . “\r\n”;

if(mail($to, $subject, $body, $headers)) {
echo $success_msg;
} else {
echo $failure_msg;
}
?>[/code]

Yes, paste the function code above this line of your code:
[php]if(mail($to, $subject, $body, $headers)) {[/php]

and then modify this line, so that it look like this:
[php]if(mail_smtp($to, $subject, $body, $headers)) {[/php]

Also, don’t forget to change smtp settings to yours (you can use your Gmail info).

Is there any possibility of having that code you pasted sent to me in a PHP file via e-mail as when I paste it into my script it’s all messed up?
Thanks-in-advance

This is how it looks:

[code]<?php
// Chnage this according to your settings

$to = ‘[email protected]’; // Change the mail according to your need.
$subject = “Contact Form”; // Mail Subject
$success_msg = ‘Your Message has been submitted and we will get back to you ASAP.

’; // The message displayed after successful mail delivery
$failure_msg = ‘

Contact Form Submitted!

Due to some reason mail is not sent.

’; // The message displayed after mail delivery failure

//Do not edit below this line.

if ( trim($_POST[‘names’]) != ‘’ ) {
$names = stripslashes(strip_tags($_POST[‘names’]));
} else {
$names = ‘No name entered’;
}
if ( trim($_POST[‘emails’]) != ‘’ ) {
$emails = stripslashes(strip_tags($_POST[‘emails’]));
} else {
$emails = ‘No email entered’;
}
if ( trim($_POST[‘phone’]) != ‘’ ) {
$phone = stripslashes(strip_tags($_POST[‘phone’]));
} else {
$phone = ‘No phone number entered’;
}
if ( trim($_POST[‘comments’]) != ‘’ ) {
$comments = nl2br(stripslashes(strip_tags($_POST[‘comments’])));
} else {
$comments = ‘No comments entered’;
}
ob_start();
?>

.style3 {color: #000000}
Name <?=$names;?>
Email <?=$emails;?>
Comments <?=$comments;?>
<? $body = ob_get_contents(); ob_end_clean();

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= ‘From: ‘.$names.’ <’.$emails.’>’ . “\r\n”;

// Sending emails via SMTP ***********************************************

function mail_smtp ($to, $subject, $mess, $hdrs=""){ require_once “Mail.php”; $host = “slocalhost”; $port = “465”; $username = "[email protected]"; $password = “********”; $headers = array ( ‘To’ => $to, ‘Subject’ => $subject, ‘MIME-Version’ => ‘1.0’, ‘Content-type’ => ‘text/html; charset=utf-8’, ‘Content-transfer-encoding’ => ‘8Bit’); if($hdrs!=’’){ $arr=explode("\n",trim($hdrs)); if($arr) foreach($arr as $line){ $arrnew=explode(": ",trim($line)); $headers[trim($arr[0])]=trim($arrnew[1]); } } $smtp = Mail::factory(‘smtp’, array (‘host’ => $host, ‘port’ => $port, ‘auth’ => true, ‘username’ => $username, ‘password’ => $password)); $mail = $smtp->send($to, $headers, $mess); if(PEAR::isError($mail)){ return false; } else{ return true; } }?>

if(mail_smtp($to, $subject, $body, $headers)) {
echo $success_msg;
} else {
echo $failure_msg;
}
?>[/code]

Does it look ok? Only it errors with the following:

if(mail_smtp($to, $subject, $body, $headers)) { echo $success_msg; } else { echo $failure_msg; } ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service