Page 1 of 1

Mail.php

Posted: Sun May 31, 2009 4:14 am
by vipul73
I had a code:

Code: Select all

<?php 
include 'all.php';
$email = $_POST["email"]; 
$from = $_POST["email"];
$tos = $_POST["tos"]; 
$subject = "Order From Website";
$to  = "XXXXXX";
$message = "
$Salutation $First_Name $Last_Name has placed an order for $package for the site $Domain 
$First_Name $Last_Name  has chosen to pay by $payment and has chosen to pay $currency $amount per $duration
The invoice number is $orderno
Contact Details
$Company
$Address1
$Address2
$City
$Zip
$State
$Country
Telephone: $Tel_Country - $Tel_Area - $Tel_No
Fax: $Fax_Country - $Fax_Area - $Fax_No
Whether agreed to Terms and Condition: $tos
 
-----------------------------------------
His IP Address was $IP
-----------------------------------------
";
 
mail($to, $subject, $message, "From: $First_Name $Last_Name <$email>");
 
?>
Now my webspace provider has switched to a secure mail mode and has send me a file mail.php to be included.

Code: Select all

<?php
require_once "Mail.php";
 
$from = "name Sender <mail@domain.com>";
$to = "name Recipient <mail@domain.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
 
$host = "XXXXXX";
$username = "XXXX";
$password = "XXXX";
 
$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>");
 }
?>
 

The chap who had done my site is not traceable. Can somebody help me merge both these codes?
:cry:

Re: Mail.php

Posted: Sun May 31, 2009 6:51 am
by Darhazer
Replace the following line in your existing code:

Code: Select all

mail($to, $subject, $message, "From: $First_Name $Last_Name <$email>");
With:

Code: Select all

 
$host = "XXXXXX";
$username = "XXXX";
$password = "XXXX";
  
$headers = array ('From' => "From: $First_Name $Last_Name <$email>",
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));
  
 $mail = $smtp->send($to, $headers, $message);
  
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }
 ?>
Your hosting provider should give you the values for host, username and password