2014-11-05 54 views
0

使用郵件功能,我能夠發送郵件。我使用了下面的代碼,但後來我到外面去冒煙,現在我不能讓這個函數工作。使用簡單的郵件功能不使用PHP發送電子郵件

林下面的代碼來發送電子郵件:

<?php 
    $name = $_POST["fuldenavn"]; 
    $email = $_POST["email"]; 
    $comments = $_POST["beskrivelse"]; 
    $subject = $_POST["virksomhed"]; 

    $modtager = "[email protected]"; 
    $emne = "". $subject .""; 

    $besked = "<h1 style='background-color: #006699; padding:10px; color:#ffffff;'> 
       Boligpakken.dk 
       </h1><b>". $emne ."</b><br><p>". $comments ."</p><br>Mvh<br>". $name ."<br>". $email .""; 

    $header = "MIME-Version: 1.0" . "\r\n"; 
    $header .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; 
    $header .= "from:". $email .""; 

    if(mail($modtager, $emne, $besked, $header)) { 
     header("Location: http://boligpakken.dk/popup-info-virk.php?page=3&small=1&sent=1"); 
    } else { 
     header("Location: http://boligpakken.dk/popup-info-virk.php?page=3&small=1&sent=0"); 
    } 
?> 

,這是我的HTML表單設置:

<form action="send-email-virk.php" method="post"> 
       <div class="left"> 
       <label> 
        <h3>Dit fulde navn</h3> 
        <input type="text" name="fuldenavn" placeholder="Dit fulde navn" maxlength="30" data-validation="required" data-validation-error-msg="*"/> 
       </label> 
       <label> 
        <h3>Din email</h3> 
        <input type="text" name="email" placeholder="Din email adresse" maxlength="40" data-validation="email" data-validation-error-msg="*"/> 
       </label> 
       <label> 
        <h3>Virksomhed</h3> 
        <input type="text" name="virksomhed" placeholder="Virksomhed" maxlength="40" data-validation="required" data-validation-error-msg="*"/> 
       </label> 
       <label> 
        <?php if($_GET['sent'] == ''): ?> 
        <input type="submit" class="button" value="Indsend - Vi kontakter dig hurtigst muligt" /> 
        <?php elseif($_GET['sent'] == '1'): ?> 
         <center><b>Tak!</b> Vi vender tilbage hurtigst muligt.</center> 
        <?php elseif($_GET['sent'] == '0'): ?> 
        <center>Der skete en fejl</center> 
        <?php endif ?> 
       </label> 
       </div><!-- end left --> 
       <div class="right"> 
       <label> 
        <h3>Beskrivelse og formål</h3> 
        <textarea name="beskrivelse" placeholder="Beskrivelse" maxlength="2030" data-validation="required" data-validation-error-msg="*"></textarea> 
       </label> 
       </div><!-- end right --> 
    <div class="clear"></div> 
     </form> 

伊夫問我的同事,但他們不能看到代碼中的任何錯誤,但我不發送任何電子郵件。

+0

您是否檢查過垃圾郵件文件夾? – 2014-11-05 11:05:44

+0

檢查你的php.ini文件,看看'郵件'配置是否正確 – iatboy 2014-11-05 11:06:55

+0

是的,我檢查垃圾郵件文件夾,但即時獲取重定向發送= 0,所以我知道郵件功能失敗。我會檢查php.ini並取回 – HereToHelpPHP 2014-11-05 11:08:21

回答

0

也許你的服務器不支持?嘗試smtp發送,例如:

<?php 

include('Mail.php'); 

$recipients = '[email protected]'; //CHANGE 

$headers['From'] = '[email protected]'; //CHANGE 
$headers['To']  = '[email protected]'; //CHANGE 
$headers['Subject'] = 'Test message'; 

$body = 'Test message'; 

// Define SMTP Parameters 

$params['host'] = 'mail.mail.com'; 
$params['port'] = '26'; 
$params['auth'] = 'PLAIN'; 
$params['username'] = '[email protected]'; //CHANGE 
$params['password'] = 'pass'; //CHANGE 

/* The following option enables SMTP debugging and will print the SMTP 
conversation to the page, it will only help with authentication issues, 
if PEAR::Mail is not installed you won't get this far. */ 

$params['debug'] = 'true'; 

// Create the mail object using the Mail::factory method 

$mail_object =& Mail::factory('smtp', $params); 

// Print the parameters you are using to the page 

foreach ($params as $p){ 
     echo "$p<br />"; 
} 

// Send the message 

$mail_object->send($recipients, $headers, $body); 
?> 
+0

我會試試這個。謝謝。雖然在去香菸之前郵件功能確實工作正常,所以這會很奇怪。 – HereToHelpPHP 2014-11-05 11:12:41

+0

我開始使用smtp郵件,因爲郵件功能在許多服務器上被禁用,並且主機提供商不想激活它。發送郵件與您的登錄更加正確 – Zhenya 2014-11-05 11:15:49

+0

這解決了我的問題。如果其他人遇到同樣的問題,可以使用這種方法! – HereToHelpPHP 2014-11-05 11:23:55

相關問題