How to Send Email from a PHP Script Using SMTP Authentication???
Har en php mail() som jeg godt kunne tænke mig at integreret med kode fra dette link: http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htmProblemet er at jeg ikke ved hvordan jeg skal gøre det :)
Nogen der kan hjælpe?
Min kode:
----------------------------------------
function kvittering($db,$page){
if( $_GET['page'] == 'kvittering') {
$sql = "select * from e_orders order by o_id desc limit 1";
$query = mysqli_query($db,$sql) or die (mysqli_error($db));
$res = mysqli_fetch_array($query);
// multiple recipients
$to = 'eksempel@gmail.com' . ', '; // note the comma
$to .= $res["o_mail"];
// subject
$subject = 'Ordrebekræftelse eksempel.dk';
// message
$message = ''; // Selve beskeden til mailen opbygges i denne variable
$message .= '<table border="0" align="center" width="980px" cellspacing="15" >';
$message .= '<tr>';
$message .= '<td><strong>Tak for din bestilling:</strong></td>';
$message .= '</tr>';
$message .= '<tr>';
$message .= '<td colspan="2"><hr></td>';
$message .= '</tr>';
$message .= '<tr>';
$message .= '<td>Bestillingsdato:';
$sql = "select * from e_orders order by o_id desc limit 1";
$query = mysqli_query($db,$sql) or die (mysqli_error($db));
$res = mysqli_fetch_array($query);
$message .= $res['o_date'];
$message .= '</td>';
$message .= '</tr>';
$message .= '<tr>';
$message .= '<td>';
$message .= $res['o_first'].$res['o_last']."<br />";
$message .= $res['o_adr'].'<br />'.$res['o_sipcode'].$res['o_city'].'<br />';
$message .= "E-mail: ".$res['o_mail']."<br />";
$message .= "Tlf.: ".$res['o_tlf']."";
$message .= '</td>';
$message .= '</tr>';
$message .= '<tr>';
$count = count(@$_SESSION['basket']['fisk_id']);
$message .= '<table width="980px" border="0" align="center" cellspacing="5">';
$message .= '<tr>';
$message .= '<td width="164" bgcolor="#77BBFF">Produkt: </td>';
$message .= '<td width="64" bgcolor="#77BBFF">Stk/Gram: </td>';
$message .= '<td width="164" bgcolor="#77BBFF">Pris:</td>';
$message .= '<td width="164" bgcolor="#77BBFF">Antal bestilte gram/fisk: </td>';
$message .= '<td width="164" bgcolor="#77BBFF" style="text-align:right;">SubTotal:</td>';
$message .= '</tr>';
$totalprice = 0;
for($i = 0; $i < $count;$i++){
$message .= "<tr>";
$message .= "<td style='text-align:left;' style='color:#000' bgcolor='#F2F4FF'>".$_SESSION['basket']['fisk_art'][$i]."</td>";
$message .= "<td style='color:#000' bgcolor='#F2F4FF'>".$_SESSION['basket']['fisk_gram'][$i]." </td>";
$message .= "<td style='color:#000' bgcolor='#F2F4FF'>".$_SESSION['basket']['fisk_pris'][$i]." Kr.</td>";
$message .= "<td style='text-align:left;' style='color:#000' bgcolor='#F2F4FF'>".$_SESSION['basket']['count'][$i]."</td>";
$price = $_SESSION['basket']['fisk_pris'][$i] / $_SESSION['basket']['fisk_gram'][$i];
$total = $price * $_SESSION['basket']['count'][$i];
$message .= "<td style='text-align:right;' style='color:#000' bgcolor='#F2F4FF'>".$total." DKK.</td>";
$totalprice = $totalprice + $total;
$message .= "</tr>";
};
$message .= "</table>";
$message .= "<table width='980px' border='0' align='center' cellspacing='0'>";
$message .= "<tr>";
$message .= "<td><hr></td>";
$message .= "</tr>";
$message .= "</table>";
$message .= "<table width='980px' border='0' align='center' cellspacing='0'>";
$message .= "<tr>";
$message .= "<td>Total Pris inkl. moms: </td>";
$message .= "<td colspan='3' style='text-align:right;'>"; $message .= "".$totalprice.""; $message .= " DKK.</td>";
$message .= "</tr>";
$message .= "</table>";
$message .= "<table width='980px' border='0' align='center' cellspacing='0'>";
$message .= "<tr>";
$message .= "<td><hr></td>";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td>Hvis der skulle være spørgsmål, er du mere end velkommen til at ringe.<br /><br /></td>";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td>Mvh. ";
$sql = "select * from text where text_id=2";
$query = mysqli_query ($db, $sql) or die (mysqli_error($db));
$res = mysqli_fetch_array ($query);
$message .= nl2br($res['text_b']);
$message .= "</td>";
$message .= "</tr>";
$message .= "</table>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$sql = "select * from e_orders order by o_id desc limit 1";
$query = mysqli_query($db,$sql) or die (mysqli_error($db));
$res = mysqli_fetch_array($query);
// Additional headers
$headers .= 'To: Victor <eksempel@gmail.com>' . "\r\n";
$headers .= 'From: eksempel <eksempel@gmail.com>' . "\r\n";
$headers .= 'Cc: "'.$res["o_mail"]. "\r\n";
// Mail it
if(mail($to, $subject, $message, $headers)){
die(":)");
}else{
die(":(");
}
};
};