Hello everybody,
I tried to improve the code and the comments!!
Here is my problem : I tried to send the mail from a form via this script. I received normally the mail across "the switch operation" (see the code) but I unfortunately didn't received this mail in copy (the Cc-Bcc) does not work!
Someone could help me, something's wrong in the code?
Thanx a lot.
<?php
// get required base data
$contactTime = date('d.m.Y H:i:s',time());
$contactLang = strtoupper($POST['lng']);
$contactClub = $POST['club'];
$contactTitle = $POST['title'];
$contactLastName = stripslashes($POST['lastname']);
$contactFirstName = stripslashes($POST['firstname']);
$contactAddress = stripslashes($POST['address']);
$contactCity = stripslashes($POST['city']);
$contactEmail = stripslashes($POST['email']);
$contactDayPhone = stripslashes($POST['dayphone']);
$contactNightPhone = stripslashes($POST['nightphone']);
//choice of checkbox
switch($contactClub)
{
case 'geneva' : $mailTo = 'geneva@anywhere.ch';
$clubName = 'Genève';
break;
case 'lausanne' : $mailTo = 'lausanne@anywhere.ch';
$clubName = 'Lausanne';
break;
case 'mystery' : $mailTo = 'mystery@anywhere.ch';
$clubName = 'Lausanne';
break;
case 'zurich' : $mailTo = 'zuerich@anywhere.ch';
$clubName = 'Zürich';
break;
case 'blues' : $mailTo = 'blues@anywhere.fr';
$clubName = 'Blues';
break;
}
//redirection when mail is gone
$redirect = 'thanks.html';
//building the mail
$mailToName = 'Anywhere';
$mailSubject = 'your chance';
$mailBody = "
<b>Anywhere 06/04</b>
<br><br>
<table cellpadding='0' cellspacing='0' border='0'>
<tr>
<td width='200'>Langue</td>
<td width='30'> : </td>
<td>$contactLang</td>
</tr>
<tr>
<td width='200'>Date/heure d'envoi</td>
<td width='30'> : </td>
<td>$contactTime</td>
</tr>
<tr>
<td colspan='3'> </td>
</tr>
<tr>
<td>Club</td>
<td> : </td>
<td>$clubName</td>
</tr>
<tr>
<td colspan='3'> </td>
</tr>
<tr>
<td>Last name</td>
<td> : </td>
<td>$contactTitle</td>
</tr>
<tr>
<td>Last name</td>
<td> : </td>
<td>$contactLastName</td>
</tr>
<tr>
<td>First name</td>
<td> : </td>
<td>$contactFirstName</td>
</tr>
<tr>
<td>Address</td>
<td> : </td>
<td>$contactAddress</td>
</tr>
<tr>
<td>Zipcode / City</td>
<td> : </td>
<td>$contactCity</td>
</tr>
<tr>
<td>E-Mail</td>
<td> : </td>
<td><a href='mailto:$contactEmail'>$contactEmail</a></td>
</tr>
<tr>
<td>Day phone</td>
<td> : </td>
<td>$contactDayPhone</td>
</tr>
<tr>
<td>Night phone</td>
<td> : </td>
<td>$contactNightPhone</td>
</tr>
</table>
"; // end mailBody
/
don't touch anything from here to the end of file !
*/
// finalize mail
$htmlContent = "<html>
<head>
<title>$mailSubject</title>
</head>
<body>
$mailBody
</body>
</html>"; // end finalization
// mail headers
$headers = array(
"Subject" => "$mailSubject",
"Date" => date("D, d M Y H:i:s O"),
"From" => "$contactFirstName $contactLastName <$contactEmail>",
"To" => "$mailToName <$mailTo>",
"Content-Type" => "text/html; charset=iso-8859-1"
);
// mail socket-openclose connection
$debug = false;
$connect = fsockopen("smtp.anywhere.ch", 25, $errno, $errstr, 30) or die("Could not talk to the sendmail server!");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "EHLO blues.anywhere.ch\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "MAIL FROM:<NOREPLY@anywhere.com>\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "RCPT TO:<$mailTo>\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "RCPT BCC:<mario@anywhere.com>\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "DATA\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
$socketheaders = "";
foreach($headers as $key=>$value )
$socketheaders .= $key.": $value\r\n";
fputs($connect, $socketheaders);
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "\r\n".str_replace("\n","",str_replace("\r\n","",$htmlContent))."\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "\r\n\r\n.\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "RSET\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
fputs($connect, "QUIT\r\n");
$rcv = fgets($connect, 1024);
if($debug) print("<br>[$rcv]");
// redirect
header("Location: $redirect");
// end form.php
?>