简单邮件功能不使用PHP发送电子邮件

时间:2014-11-05 11:03:57

标签: php forms email

使用邮件功能,我能够发送邮件。我使用了以下代码,但后来我出去吸烟,现在我无法使用该功能。

我使用以下代码发送电子邮件:

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

    $modtager = "js@stokerinvest.com";
    $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>

我问过我的同事,但他们看不到代码中的任何错误,但我不发送任何电子邮件。

1 个答案:

答案 0 :(得分:0)

也许你的服务器不支持这个?尝试smtp发送,例如:

<?php

include('Mail.php');

$recipients = 'mail@mail.com'; //CHANGE

$headers['From']    = 'info@mail.com'; //CHANGE
$headers['To']      = 'info@mail.com'; //CHANGE
$headers['Subject'] = 'Test message';

$body = 'Test message';

// Define SMTP Parameters

$params['host'] = 'mail.mail.com';
$params['port'] = '26';
$params['auth'] = 'PLAIN';
$params['username'] = 'info@mail.com'; //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);
?>