2014-11-05 143 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

相关问题