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
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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

smtp is the email proticol, not a program.

 

If you send an email via your server (foo.com) with an address in the 'From' header that isn't from that server (bar.com) it will be suspect to any mail client.

Link to comment
Share on other sites

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>");
}

}

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.