Jump to content

SMTP & sendmail Help


herghost

Recommended Posts

Hi all,

 

A script i am uses uses this to send validation emails to new signups:

 

function xMail($to, $subj, $msg, $from="", $charset="UTF-8", $xtraheaders="")
{
$headers  = "";
if($from) $headers .= "From: {$from}\n";
    $headers .= "Date: " . date("r") . "\n";
    $headers .= "Message-ID: " . generateMessageID() . "\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=\"$charset\"\n";
$headers .= "Content-Transfer-Encoding: 7bit\n";
$headers .= $xtraheaders;
$headers .= "\n";

$ret = mail ($to, $subj, $msg, $headers, "-f$from");
return $ret;

}

function HTMLMail($to, $subj, $msg, $from="", $charset="UTF-8", $xtraheaders="")
{
$headers  = "";
if($from) $headers .= "From: {$from}\n";
    $headers .= "Date: " . date("r") . "\n";
    $headers .= "Message-ID: " . generateMessageID() . "\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=\"$charset\"\n";
$headers .= "Content-Transfer-Encoding: 7bit\n";
$headers .= $xtraheaders;

$ret = mail ($to, $subj, $msg, $headers, "-f$from");
return $ret;

}

 

I am right in saying that it is using the sendmail function? My host will not allow emails to be sent from scrips from nobody@domain etc so I was thinking about using my SMTP mail instead. Now normally I would assume that I would just use something like this:

 

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

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

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

 

But as far as I know (I am very very new to php!) doesnt this rely on the information being presented as so:

 

$from = " Sender <[email protected]>";
$to = "Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

 

How do I go about changing the $header tags in the actual script to things I understand like $to and $subject?

 

I am even looking at the right piece of code?!!

 

Thanks All!

Link to comment
https://forums.phpfreaks.com/topic/118462-smtp-sendmail-help/
Share on other sites

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.