开发者

send mail from client and server in php

i have request form in my site. i submit the form in php the mail send to server.i need a code the mail send to server and "thank you for request" mail send to client at a time .

Example:

<?php
ob_start();
$namecp = $_POST['namecp']; 
$namec  = $_POST['namec']; 
$mobile = $_POST['mobile'];
$lname = $_POST['lname']; 
$problem = $_POST['problem']; 
$Failure_date = $_POST['Failure_date'];
$Failure_Hours = $_POST['Failure_Hours'];
$Failure_Minutes = $_POST['Failure_Minutes'];
$Failure_sec = $_POST['Failure_sec'];
$Service_required_date = $_POST['Service_required_date'];
$Service_Hours = $_POST['Service_Hours'];
$Service_Minutes = $_POST['Service_Minutes'];
$Service_sec = $_POST['Service_sec'];
$Door_No = $_POST['Door_No'];
$Area_Nagar = $_POST['Area_Nagar'];
$city = $_POST['city'];
$state_district = $_POST['state_district'];
$Postal_Code = $_POST['Postal_Code'];
$Engine_Serial_number = $_POST['Engine_Serial_number'];
$Contact_phone_number= $_POST['Contact_phone_number'];
$Contact_phone_number_full= $_POST['Contact_phone_number_full'];
$cemail= $_POST['cemail'];
$ps= ':';
$ps1= '/';
$ps2= '-';
$pno= '+91&nbsp;';

function sendHTMLemail($HTML,$from,$to,$subject)
{
// First we have to build our email headers
// Set out "from" address

    $headers = "From: $from\r\n"; 

// Now we specify our MIME version

    $headers .= "MIME-Version: 1.0\r\n"; 

// Create a boundary so we know where to look for
// the start of the data

    $boundary = uniqid("HTMLEMAIL"); 

// First we be nice and send a non-html version of our email

    $headers .= "Content-Type: multipart/alternative;".
                "boundary = $boundary\r\n\r\n"; 

    $headers .= "This is a MIME encoded message.\r\n\r\n"; 

    $headers .= "--$boundary\r\n".
                "Content-Type: text/plain; charset=ISO-8859-1\r\n".
                "Content-Transfer-Encoding: base64\r\n\r\n"; 

    $headers .= chunk_split(base64_encode(strip_tags($HTML))); 

// Now we attach the HTML version

    $headers .= "--$boundary\r\n".
                "Content-Type: text/html; charset=ISO-8859-1\r\n".
                "Content-Transfer-Encoding: base64\r\n\r\n"; 

    $headers .= chunk_split(base64_encode($HTML)); 

// And then send the email ....

    mail($to,$subject,"",$headers);

}

// Connect to server and select database.

// values sent from form

$email='test@gmail.com';

// ---------------- SEND MAIL FORM ----------------
$header1 = 'Service Request';
// send e-mail to ...
$to=$email;
// Your subject
$subject="service request";

// From

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "SPC";
   $message = "<table width='500' border='0' cellspacing='0' cellpadding='0'>";
   $message .= "<tr><td>Name of the contact person</td><td>:</td><td>".$namecp."</td></tr>";
   $message .= "<tr><td>Name of the Customer</td><td>:</td><td>".$namec."</td></tr>";
   $message .= "<tr><td>Mobile number</td><td>:</td><td>".$pno.$mobile."</td></tr>";
   $message .= "<tr><td>Problem summary</td><td>:</td><td>".$problem."</td></tr>";
   $message .= "<tr><td>Failure date & time</td><td>:</td><td>".$Failure_date.$ps1.$Failure_Hours.$ps.$Failure_Minutes.$ps.$Failure_sec."</td></tr>";
   $message .= "<tr><td>Service required date & time</td><td>:</td><td>".$Service_required_date.$ps1.$Service_Hours.$ps.$Service_Minutes.$ps.$Service_sec."</td></tr>";
   $message .= "<tr><td>D开发者_开发技巧oor No. & Street Name</td><td>:</td><td>".$Door_No."</td></tr>";
   $message .= "<tr><td>Area/Nagar</td><td>:</td><td>".$Area_Nagar."</td></tr>";
   $message .= "<tr><td>City</td><td>:</td><td>".$city."</td></tr>";
   $message .= "<tr><td>State/District</td><td>:</td><td>".$state_district."</td></tr>";
   $message .= "<tr><td>Postal Code/Zip Code</td><td>:</td><td>".$Postal_Code."</td></tr>";
   $message .= "<tr><td>Engine Serial number</td><td>:</td><td>".$Engine_Serial_number."</td>
   </tr>";
   $message .= "<tr><td>Phone number</td><td>:</td><td>".$Contact_phone_number.$ps2.$Contact_phone_number_full."</td></tr>";
   $message .= "<tr><td>Email</td><td>:</td><td>".$cemail."</td></tr>";
   $message .= "</table>";

//echo $message;
// send email

sendHTMLemail($message,$header1,$to,$subject);

//header('Location: ');
ob_end_flush();  
?>


Alot of email functionality can be fast-tracked using PHPMailer.

In which case, you would replace the code you have provided with:

<?php
ob_start();

$namecp = $_POST['namecp']; 
$namec  = $_POST['namec']; 
$mobile = $_POST['mobile'];
$lname = $_POST['lname']; 
$problem = $_POST['problem']; 
$Failure_date = $_POST['Failure_date'];
$Failure_Hours = $_POST['Failure_Hours'];
$Failure_Minutes = $_POST['Failure_Minutes'];
$Failure_sec = $_POST['Failure_sec'];
$Service_required_date = $_POST['Service_required_date'];
$Service_Hours = $_POST['Service_Hours'];
$Service_Minutes = $_POST['Service_Minutes'];
$Service_sec = $_POST['Service_sec'];
$Door_No = $_POST['Door_No'];
$Area_Nagar = $_POST['Area_Nagar'];
$city = $_POST['city'];
$state_district = $_POST['state_district'];
$Postal_Code = $_POST['Postal_Code'];
$Engine_Serial_number = $_POST['Engine_Serial_number'];
$Contact_phone_number= $_POST['Contact_phone_number'];
$Contact_phone_number_full= $_POST['Contact_phone_number_full'];
$cemail= $_POST['cemail'];
$ps= ':';
$ps1= '/';
$ps2= '-';
$pno= '+91&nbsp;';

// Requires the PHPMailer Class
require_once( 'class.phpmailer.php' );
// Create a PHPMailer Object
$mail = new PHPMailer(); // defaults to using php "mail()"
// Set the Standard Email Values
$mail->SetFrom( 'name@yourdomain.com' , 'Your System Name' );
$mail->Subject = 'This is the Mail for Recipient Number One';

// Set Details for Email
$mail->AddAddress( 'mail1@server1.com' , 'Recipient Number One' );

// Create the Email Body Content
$message_html  = '<table width="500" border="0" cellspacing="0" cellpadding="0">';
$message_html .= '<tr><td>Name of the contact person</td><td>:</td><td>'.$namecp.'</td></tr>';
$message_html .= '<tr><td>Name of the Customer</td><td>:</td><td>'.$namec.'</td></tr>';
$message_html .= '<tr><td>Mobile number</td><td>:</td><td>'.$pno.$mobile.'</td></tr>';
$message_html .= '<tr><td>Problem summary</td><td>:</td><td>'.$problem.'</td></tr>';
$message_html .= '<tr><td>Failure date & time</td><td>:</td><td>'.$Failure_date.$ps1.$Failure_Hours.$ps.$Failure_Minutes.$ps.$Failure_sec.'</td></tr>';
$message_html .= '<tr><td>Service required date & time</td><td>:</td><td>'.$Service_required_date.$ps1.$Service_Hours.$ps.$Service_Minutes.$ps.$Service_sec.'</td></tr>';
$message_html .= '<tr><td>Door No. & Street Name</td><td>:</td><td>'.$Door_No.'</td></tr>';
$message_html .= '<tr><td>Area/Nagar</td><td>:</td><td>'.$Area_Nagar.'</td></tr>';
$message_html .= '<tr><td>City</td><td>:</td><td>'.$city.'</td></tr>';
$message_html .= '<tr><td>State/District</td><td>:</td><td>'.$state_district.'</td></tr>';
$message_html .= '<tr><td>Postal Code/Zip Code</td><td>:</td><td>'.$Postal_Code.'</td></tr>';
$message_html .= '<tr><td>Engine Serial number</td><td>:</td><td>'.$Engine_Serial_number.'</td></tr>';
$message_html .= '<tr><td>Phone number</td><td>:</td><td>'.$Contact_phone_number.$ps2.$Contact_phone_number_full.'</td></tr>';
$message_html .= '<tr><td>Email</td><td>:</td><td>'.$cemail.'</td></tr>';
$message_html .= '</table>';
$mail->MsgHTML( $message_html );
$message_text  = "Name of the contact person: $namecp\n";
$message_text .= "Name of the Customer: $namec\n";
$message_text .= "Mobile number: {$pno}{$mobile}\n";
$message_text .= "Problem summary: $problem\n";
$message_text .= "Failure date & time: {$Failure_date}{$ps1}{$Failure_Hours}{$ps}{$Failure_Minutes}{$ps}{$Failure_sec}\n";
$message_text .= "Service required date & time: {$Service_required_date}{$ps1}{$Service_Hours}{$ps}{$Service_Minutes}{$ps}{$Service_sec}\n";
$message_text .= "Door No. & Street Name: $Door_No\n";
$message_text .= "Area/Nagar: $Area_Nagar\n";
$message_text .= "City: $city\n";
$message_text .= "State/District: $state_district\n";
$message_text .= "Postal Code/Zip Code: $Postal_Code\n";
$message_text .= "Engine Serial number: $Engine_Serial_number\n";
$message_text .= "Phone number: {$Contact_phone_number}{$ps2}{$Contact_phone_number_full}\n";
$message_text .= "Email: $cemail\n";
$mail->AltBody = $message_text;

// Sending the Email
if( !$mail->Send() ) {
  // Failed to Send
  echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
  // Sent OK
  echo 'Message sent!';
}

ob_end_flush();  
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜