Jump to content

PHP mail not working, SMTP help


DeanWhitehouse

Recommended Posts

I have a email script, but there is a problem, PHP mail doesn't seem to want to work on the host, but SMTP does, as i have two CMS using it on my account.

 

How can i set up my mail using SMTP??

 

This is my current mail code

       	
$to = htmlspecialchars($_POST['to']);
$subject = htmlspecialchars($_POST['subject']);
$from = htmlspecialchars($_POST['from']);
$message = htmlspecialchars($_POST['message']);
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\n";
$header .= "From: $from <$from>\n";
$header .= "X-Mailer: PHP's mail() Function\n";
mail($to,$subject,$message,$header);

Link to comment
https://forums.phpfreaks.com/topic/110664-php-mail-not-working-smtp-help/
Share on other sites

After speaking to my host, i have resolved the problem in a sense.

 

        $fr = "my site email";
$to = htmlspecialchars($_POST['to']);
$subject = htmlspecialchars($_POST['subject']);
$from = htmlspecialchars($_POST['from']);
$message = htmlspecialchars($_POST['message']);
        

        mail($to,$subject,$message,$header);
        $header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\n";
$header .= "From: $fr <$fr>\n";
$header .= "X-Mailer: PHP's mail() Function\n";
$header .= "Reply-To: $from";

the problems i am having are:

The email is being classed as a suspicous mail. Any ideas how to stop this.

Also the bit in the email where it says who it is from is my site email, how can i get it to show there email ($from) but still send from mine?

 

The email is being classed as a suspicous mail. Any ideas how to stop this.

Also the bit in the email where it says who it is from is my site email, how can i get it to show there email ($from) but still send from mine?

 

The email will always be regarded as suspicious if the 'from' header does not match the hostname of the smtp sending the email.

Yes, but i have read of ways to send an email , where you enter your SMTP details then send it .

 

Something like this http://email.about.com/od/emailprogrammingtips/qt/et073006.htm .

 

I want to do what my cms does, which is send an email from any email address using my smtp settings.

Ok, i followed that tutorial and get an error

 

Fatal error: Undefined class name 'mail' in /home/www/djw-webdesign.awardspace.com/Mail App/mailapp.php on line 100

 

this is the part of the code it refers to

$host = ""; //my details removed
$username = ""; // my details removed
$password = ""; //my details removed

//first off check if they have posted
if(isset($_POST['send']))
{
$to = htmlspecialchars($_POST['to']);
$subject = htmlspecialchars($_POST['subject']);
$from = htmlspecialchars($_POST['from']);
$message = htmlspecialchars($_POST['message']);
$error = 0;


if($error == 0)
{
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\n";
$header .= "From: $from <$from>\n";
$header .= "X-Mailer: PHP's mail() Function\n";
$header .= "Reply-To: $from";

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

$mail = $smtp->send($to, $subject, $header, $message);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {
  echo("<p>Message successfully sent!</p>");
}

}

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.