2012-01-10 18 views
31

मैं PHP के लिए नया हूं और मैं मेल फ़ंक्शन का उपयोग कर उन ईमेल भेजने के लिए उपयोग कर रहा हूं जो काम नहीं कर रहे हैं। मैं एक सफलता संदेश मिलता है, लेकिन अभी भी यह काम नहीं करताPHP मेल किसी कारण से काम नहीं कर रहा है

एक ही कोड

<?php 
    $email_to = "[email protected]"; 
    $email_subject = "Test mail"; 
    $email_body = "Hello! This is a simple email message."; 


    if(mail($email_to, $email_subject, $email_body)){ 
     echo "The email($email_subject) was successfully sent."; 
    } else { 
     echo "The email($email_subject) was NOT sent."; 
    } 
?> 

मैं कुछ भी याद आ रही है, मैं इस समारोह के लिए किसी भी फाइल को शामिल करने की जरूरत है .. मैं asp.net से हूँ & यह मूलभूत लिपि है जो वेबसाइट पर मिली है।

मैं अन्य मेल करने के वे या तो काम नहीं किया ..

मैं नहीं स्थानीय होस्ट

+0

आपके विन्यास –

+0

जाँच आपको लगता है कि कहाँ प्रयोग करते हैं? स्थानीय मशीन पर या सर्वर पर? – zozo

+0

वेब सर्वर पर – Learning

उत्तर

9

पर वेबसाइट पर इस स्क्रिप्ट चला रहा हूँ यह शायद एक विन्यास त्रुटि है संबंधित स्क्रिप्ट की कोशिश की। यदि आप PHP mail फ़ंक्शन का उपयोग करने पर जोर देते हैं, तो आपको php.ini संपादित करना होगा।

यदि आप एक आसान और अधिक बहुमुखी विकल्प (मेरी राय में) की तलाश में हैं, तो आपको PHPMailer का उपयोग करना चाहिए।

1

अपनी php.ini फ़ाइल में अपनी एसएमटीपी सेटिंग्स की जांच करें। आपके होस्ट के पास कुछ दस्तावेज होना चाहिए कि किस क्रेडेंशियल्स का उपयोग करना है। शायद आप अपनी त्रुटि लॉग फ़ाइल देख सकते हैं, इसमें अधिक जानकारी उपलब्ध हो सकती है।

2

मेल फ़ंक्शन मेल की वास्तविक डिलीवरी की गारंटी नहीं देता है। यह सब संदेश को बाहरी कार्यक्रम (आमतौर पर sendmail) को पास करना है। इसे काम करने के लिए आपको एक उचित कॉन्फ़िगर किए गए SMTP सर्वर की आवश्यकता है। यह भी ध्यान रखें कि यह SMTP प्रमाणीकरण का समर्थन नहीं करता है। आप स्विफ्टमेलर की पीईआर :: मेल लाइब्रेरी देख सकते हैं, उनमें से दोनों आपको अधिक विकल्प देते हैं।

2

"सिर्फ इसलिए कि आपको एक ईमेल भेज अर्थ यह नहीं है कि यह आ जाएगा।"

भेजा जा रहा है मेल एक गंभीर काम है - जैसे जिस डोमेन का उपयोग आप अपने "से:" पते के रूप में कर रहे हैं, उसे आपके वेबसर्वर से ई-मेल अस्वीकार करने के लिए कॉन्फ़िगर किया जा सकता है। एक लंबे अवलोकन के लिए (और कुछ युक्तियों को जांचने के लिए), http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html

5

यह आपकी php.ini फ़ाइल में आपकी SMTP कॉन्फ़िगरेशन का मुद्दा हो सकता है।

आप PHP के लिए नया, आप पीएचपी स्थापना फ़ोल्डर के अपने रूट निर्देशिका में php.ini फ़ाइल को खोजने के बाद से कर सकते हैं और एसएमटीपी के लिए जाँच = और SMTP_PORT = और

SMTP = your mail server e.g) mail.yourdomain.com 
smtp_port = 25(check your admin for original port) 

को मान बदलने के मामले अपने सर्वर की आवश्यकता होती है में मेल भेजने के लिए प्रमाणीकरण, पीईआर मेल फ़ंक्शन का उपयोग करें।

59

आप Ubuntu उपयोग कर रहे हैं और यह प्रतीत sendmail /usr/sbin/sendmail में नहीं है, तो इस आदेश के साथ टर्मिनल का उपयोग कर sendmail स्थापित:

sudo apt-get install sendmail 

और फिर पीएचपी पेज जहां mail() लिखा है फिर से लोड चलाते हैं। अपने स्पैम फ़ोल्डर को भी देखें।

+2

मेरे लिए फिक्स्ड, धन्यवाद। घंटों तक इस पर फंस गया था .. इतना आसान फिक्स लॉल - बस जोड़ने के लिए, मैं 'ओवीएच वीपीएस' का उपयोग कर रहा हूं। तो अगर भविष्य में कोई भी इसे देखता है, हैलो :) –

0

HostGator लिए, आप अपने हेडर के लिए निम्नलिखित का उपयोग करने की जरूरत है:

$headers = 'From: [email protected]' . " " . 
'Reply-To: [email protected]' . " " . 
'X-Mailer: PHP/' . phpversion(); 

यह केवल मेरे लिए काम किया है जब उपयोगकर्ता से था मेजबान ई-मेल, जबकि इन्हें जवाब दें कुछ अलग हो सकता है जैसे प्रेषक: डोमेन @ डोमेन।कॉम, प्रत्युत्तर दें: [email protected]

http://support.hostgator.com/articles/specialized-help/technical/php-email-from-header http://support.hostgator.com/articles/specialized-help/technical/how-to-use-sendmail-with-php

0

मैं अब थोड़ी देर के लिए इस का उपयोग कर रहा है, अगर यह वास्तविक पीएचपी संस्करणों के साथ तारीख तक अब भी है पता नहीं है। आप एक एक फ़ाइल सेटअप में इसका उपयोग कर सकते हैं, या बस यह contact.php और index.php

contact.php की तरह दो फ़ाइलों में विभाजित अप | कोड

<?php 
error_reporting(E_ALL^E_NOTICE); 


if(isset($_POST['submitted'])) { 


if(trim($_POST['contactName']) === '') { 
    $nameError = '<span style="margin-left:40px;">You have missed your name.</span>'; 
    $hasError = true; 
} else { 
    $name = trim($_POST['contactName']); 
} 

if(trim($_POST['topic']) === '') { 
    $topicError = '<span style="margin-left:40px;">You have missed the topic.</span>'; 
    $hasError = true; 
} else { 
    $topic = trim($_POST['topic']); 
} 

$telefon = trim($_POST['phone']); 
$company = trim($_POST['company']); 


if(trim($_POST['email']) === '') { 
    $emailError = '<span style="margin-left:40px;">You have missed your email adress.</span>'; 
    $hasError = true; 
} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) { 
    $emailError = '<span style="margin-left:40px;">You have missspelled your email adress.</span>'; 
    $hasError = true; 
} else { 
    $email = trim($_POST['email']); 
} 


if(trim($_POST['comments']) === '') { 
    $commentError = '<span style="margin-left:40px;">You have missed the comment section.</span>'; 
    $hasError = true; 
} else { 
    if(function_exists('stripslashes')) { 
     $comments = utf8_encode(stripslashes(trim($_POST['comments']))); 
    } else { 
     $comments = trim($_POST['comments']); 
    } 
} 


if(!isset($hasError)) { 

    $emailTo = '[email protected]'; 
    $subject = 'Example.com - '.$name.' - '.$betreff; 
    $sendCopy = trim($_POST['sendCopy']); 
    $body = "\n\n This is an email from http://www.example.com \n\nCompany : $company\n\nName : $name \n\nEmail-Adress : $email \n\nPhone-No.. : $phone \n\nTopic : $topic\n\nMessage of the sender: $comments\n\n"; 
    $headers = "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"; 

    mail($emailTo, $subject, $body, $headers); 



    $emailSent = true; 
} 
} 
?> 

स्टाइल शीट

} 
.formblock{display:block;padding:5px;margin:8px; margin-left:40px;} 
.text{width:500px;height:200px;padding:5px;margin-left:40px;} 
.center{min-height:12em;display:table-cell;vertical-align:middle;} 
.failed{ margin-left:20px;font-size:18px;color:#C00;} 
.okay{margin-left:20px;font-size:18px;color:#090;} 
.alert{border:2px #fc0;padding:8px;text-transform:uppercase;font-weight:bold;} 
.error{font-size:14px;color:#C00;} 

label 
{ 
margin-left:40px; 
} 

textarea 

{ 
margin-left:40px; 
} 

index.php | फार्म कोड

<?php header('Content-Type: text/html;charset=UTF-8'); ?> 
<!DOCTYPE html> 
<html lang="de"> 
<head> 
<script type="text/javascript" src="js/jquery.js"></script> 
</head> 
<body> 


<form action="contact.php" method="post"> 

<?php if(isset($emailSent) && $emailSent == true) { ?> 

<span class="okay">Thank you for your interest. Your email has been send !</span> 

<br> 

<br> 

<?php } else { ?> 

<?php if(isset($hasError) || isset($captchaError)) { ?> 

<span class="failed">Email not been send. Please check the contact form.</span> 

<br> 

<br> 

<?php } ?> 

<label class="text label">Company</label> 

<br> 

<input type="text" size="30" name="company" id="company" value="<?php if(isset($_POST['company'])) echo $_POST['comnpany'];?>" class="formblock" placeholder="Your Company"> 

<label class="text label">Your Name <strong class="error">*</strong></label> 

<br> 

<?php if($nameError != '') { ?> 

<span class="error"><?php echo $nameError;?></span> 

<?php } ?> 

<input type="text" size="30" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="formblock" placeholder="Your Name"> 

<label class="text label">- Betreff - Anliegen - <strong class="error">*</strong></label> 

<br> 

<?php if($topicError != '') { ?> 

<span class="error"><?php echo $betrError;?></span> 

<?php } ?> 

<input type="text" size="30" name="topic" id="topic" value="<?php if(isset($_POST['topic'])) echo $_POST['topic'];?>" class="formblock" placeholder="Your Topic"> 

<label class="text label">Phone-No.</label> 

<br> 

<input type="text" size="30" name="phone" id="phone" value="<?php if(isset($_POST['phone'])) echo $_POST['phone'];?>" class="formblock" placeholder="12345 678910"> 

<label class="text label">Email-Adress<strong class="error">*</strong></label> 

<br> 

<?php if($emailError != '') { ?> 

<span class="error"><?php echo $emailError;?></span> 

<?php } ?> 

<input type="text" size="30" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="formblock" placeholder="[email protected]"> 

<label class="text label">Your Message<strong class="error">*</strong></label> 

<br> 

<?php if($commentError != '') { ?> 

<span class="error"><?php echo $commentError;?></span> 

<?php } ?> 

<textarea name="comments" id="commentsText" class="formblock text" placeholder="Leave your message here..."><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea> 

<button class="formblock" name="submit" type="submit">Send Email</button> 
<input type="hidden" name="submitted" id="submitted" value="true"> 
<?php } ?> 

</form> 
</body> 
</html> 

JAVASCRIPT

<script type="text/javascript"> 

<!--//--><![CDATA[//><!-- 

$(document).ready(function() { 

$('form#contact-us').submit(function() { 

$('form#contact-us .error').remove(); 
var hasError = false; 

$('.requiredField').each(function() { 

if($.trim($(this).val()) == '') { 
var labelText = $(this).prev('label').text(); 

$(this).parent().append('<br><br><span style="margin-left:20px;">You have missed '+labelText+'.</span>.'); 

$(this).addClass('inputError'); 
hasError = true; 

} else if($(this).hasClass('email')) { 

var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/; 
if(!emailReg.test($.trim($(this).val()))) { 

var labelText = $(this).prev('label').text(); 

$(this).parent().append('<br><br><span style="margin-left:20px;">You have entered a wrong '+labelText+' adress.</span>.'); 

$(this).addClass('inputError'); 
hasError = true; 
} 
} 
}); 
if(!hasError) { 

var formInput = $(this).serialize(); 

$.post($(this).attr('action'),formInput, function(data){ 

$('form#contact-us').slideUp("fast", function() {     
$(this).before('<br><br><strong>Thank You!</strong>Your Email has been send successfuly.'); 

}); 

}); 

} 
return false; 

}); 

}); 

//-->!]]> 

</script> 
संबंधित मुद्दे