Mail.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Mail.php

Post 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:
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Mail.php

Post 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
Post Reply