0
所以我試圖用phpMailer後使用郵件(ARG)的最後幾個網站,但這個下一個網站,我希望能夠附加到一個文件電子郵件和我認爲phpMailer會使它更容易完成這一點。PHPMailer不工作使用defaukt郵件()在一個簡單的形式
現在我有一個非常簡單的表單和sendmail.php頁面不起作用。
下面的代碼...
HTML -----------------------------
<form role="form" action="_/includes/sendmail.php" enctype="multipart/form-data" method="POST" autocomplete="on">
<div class="form-group">
<label class="emph1">First and Last Name:</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="First and Last Name">
</div>
<div class="form-group">
<label class="emph1">Email Address:</label>
<input type="email" class="form-control" id="exampleInputPassword1" placeholder="Email">
</div>
<div class="form-group">
<label class="emph1">File/Form Attachments:</label>
<?php
//Maximum file size (in bytes) must be declared before the file input field and can't be large than the setting for
// upload_max_filesize in php.ini.
// PHP will stop and compain once file is exceeded
// 1 mb is actually 1,048,576 bytes.
?>
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
<input type="file" id="exampleInputFile" name="file_upload">
<p class="help-block">Please use .jpg, .pdf, or Word based files.</p>
<p> <?php echo $message;?>
</div>
<div class="form-group">
<label class="emph1">Reason for contacting Derek Davis, PLLC:</label>
<div class="checkbox">
<label>Estate Planning<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Family Law<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Criminal Defense<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Collections<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Landlord-Tenant<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Other<input id="checkbox-other" type="checkbox"></label>
</div>
<!-- jQuery input feature (displays when "other" checkbox is checked) --->
<div class="form-group" id="input-other" style="display:none;">
<label class="emph1" for="">If 'other' please specify:</label>
<input type="text" class="form-control" id="otherProject" name="otherProject" placeholder="Enter short description here." value="" />
</div>
</div>
<!-- End jQuery input feature -->
<div class="form-group">
<label class="emph1">Please leave us a brief message:</label>
<textarea class="full-width" type="text" name="message" rows="10" placeholder="Please be as specific as possible..." required>
</textarea><br />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
PHP --------------------------
<?php ob_start()?>
<?php
function redirect_to($new_location) {
header("Location:" . $new_location);
exit;
}
require_once("_/includes/phpmailer/class.smtp.php");
require_once("_/includes/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
if (isset($_POST['message'])){
$body = $_POST['message'];
}
$mail->isMail();
// Set PHPMailer to use the sendmail transport
//Set who the message is to be sent from
//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'First Last');
//Set the subject line
$mail->addAddress('[email protected]', 'John Doe');
$mail->Subject = 'PHPMailer sendmail test';
//Replace the plain text body with one created manually
$mail->Body = $body;
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment($temp_file, $temp_file_name);
//send the message, check for errors
if ($mail->Send()) {
redirect_to("../../contact.php");
} else {
redirect_to("../../index.html");
}
?>
<?php ob_end_flush(); ?>
我知道最好你想建立一個SMTP並分配變量SMTP信息,但現在我只是想讓這個補丁的東西工作。我在php的末尾創建了一個布爾值,所以我至少知道它是否執行,但頁面不會重定向...任何建議都會受到歡迎!由於
不要忘記啓用例外'$郵件=新的PHPMailer(真);' – tlenss
有趣的是,我在工作現在,但我今晚會嘗試這個。謝謝!! –
我收到錯誤 - 無法實例化郵件功能。但是,如果在同一臺服務器上託管的另一個站點使用php的mail()工作併發送數據,爲什麼phpmailer的默認郵件()不起作用? –