14-09-2009, 08:54
|
|
|
חבר מתאריך: 04.03.05
הודעות: 41
|
|
שליחת מייל באמצעות mail() נכשלת ללא הודעת שגיאה
שלום לכולם.
אני די מתחיל בעולם בניית האתרים וב PHP בכלל אבל יש לי ידע בתכנות.
אני משתמש בקוד PHP שמצאתי באינטרנט על מנת לשלוח מיילים מדף פידבק (שכתוב ב HTML).
קוד HTML:
</script>
<div id="content">
<form action="feedback.php" method="post" style="background-color: #4A4A4A; background-repeat: repeat-x; margin: 100px; color: #CCC; font-weight: bold;">
<table border="1" align="center" cellpadding="8" cellspacing="8" summary="feedback form">
<tr>
<td bgcolor="#1A1A1A"><strong>
<label for="tswname"><font color="#aaaaaa">Name:</font></label>
</strong></td>
<td bgcolor="#1A1A1A"><input type="text" name="fullname" id="tswname" size="25" /></td>
</tr>
<tr>
<td bgcolor="#1A1A1A"><strong>
<label for="tswemail"><font color="#aaaaaa">Email address:</font></label>
</strong></td>
<td bgcolor="#1A1A1A"><input type="text" id="tswemail" name="email" size="25" /></td>
</tr>
<tr>
<td colspan="2" bgcolor="#1A1A1A"><strong>
<label for="tswcomments"><font color="#aaaaaa">Comments:</font></label>
<br />
<textarea rows="15" cols="45" name="comments" id="tswcomments"></textarea>
</strong></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#1A1A1A"><input type="submit" value="Send Feedback" /></td>
</tr>
</table>
</form>
קוד PHP:
<?php
// ------------- CONFIGURABLE SECTION ------------------------
$mailto = 'shidlo@gmail.com' ;
$subject = "Feedback Form" ;
$formurl = "http://shidlo.webatu.com/contact_form/contact.html" ;
$errorurl = "http://shidlo.webatu.com/error.html" ;
$thankyouurl = "http://shidlo.webatu.com/contact_form/recieved.html" ;
$email_is_required = 1;
$name_is_required = 1;
$comments_is_required = 1;
$uself = 0;
$use_envsender = 1;
$use_sendmailfrom = 1;
$use_webmaster_email_for_from = 1;
$use_utf8 = 0;
$my_recaptcha_private_key = '' ;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {
ini_set( 'sendmail_from', $mailto );
}
$envsender = "-f$mailto" ;
$fullname = (isset($_POST['fullname']))? $_POST['fullname'] : $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (($email_is_required && (empty($email) || !preg_match('/@/', $email))) || ($name_is_required && empty($fullname)) || ($comments_is_required && empty($comments))) {
header( "Location: $errorurl" );
exit ;
}
if ( preg_match( "/[\r\n]/", $fullname ) || preg_match( "/[\r\n]/", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (empty($email)) {
$email = $mailto ;
}
$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;
if (function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $fullname\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
$headers =
"From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .
$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;
if ($use_envsender) {
print($mailto);
print("\n\r");
print($subject);
print("\n\r");
print($messageproper);
print("\n\r");
print($headers);
print("\n\r");
print($envsender);
print("\n\r");
if (mail($mailto, $subject, $messageproper, $headers, $envsender ))
print ("made it 1");
else
print ("fail 1");
}
else {
print($mailto);
print("\n\r");
print($subject);
print("\n\r");
print($messageproper);
print("\n\r");
print($headers);
print("\n\r");
if (mail($mailto, $subject, $messageproper, $headers ))
print ("made it 2");
else
print ("fail 2");
}
//header( "Location: $thankyouurl" );
exit ;
?>
הוספתי הדפסות בסוף ובדיקה האם הפונקיה mail() הצליחה... היא לא.
כל המשתנים מקבלים בדיוק את הערכים שהם אמורים לקבל.
האתר נמצא על שרת חינמי שמפעיל את כל ההגדרות (אותה מערכת כבר שלחה לי מיילים מהאתר שלי באותו אירוח)
האם למישהו יש מושג מה הבעיה??
אני אשמח אם תוכלו לעזור לי כאן או במייל shidlo@gmail.com
תודה רבה ויום טוב
רועי שידלובסקי
|