PHPMailer:在本地主机上工作,单击域上的 "submit" 按钮后卡住,出现错误 503,电子邮件在 4 分钟后到达
PHPMailer: Working on localhost, stuck after clicking "submit" button on the domain, gives Error 503, E-Mail arrives after 4mins
所以我已经尝试了两天来摆脱这个问题。
如前所述,该代码在我的 xampp apache 本地主机上运行良好。电子邮件立即发送。
但是,在我拥有的域上,一旦我按下提交,它就会加载和加载,并且在 5 分钟左右后超时,或者更确切地说是“503 服务不可用”。
我检查了我的本地 PHP 错误日志,一切正常。
不过我无法访问服务器上的错误日志。
表单代码如下:
<div class="form-group">
<label>Ihr Name</label>
<input type="text" name="name" placeholder="Vorname Nachname" class="form-control" />
</div>
<div class="form-group">
<label>Ihre E-Mail Address</label>
<input type="email" name="email" class="form-control" placeholder="IhreEmail@server.com" />
</div>
<div class="col-md-6">
<div class="form-group">
<label>Ihre Nummer</label>
<input type="text" name="mobile" placeholder="Ihre Mobile 079 *** ** **" class="form-control" required/>
</div>
<hr/>
<div class="form-group">
<label><i class="far fa-file"></i>Ihr Dokument für die Übersetzung</label>
<input type="file" name="resume" accept=".doc,.docx,.pdf,.jpg,.bmp"/>
</div>
</div>
<div class="form-group">
<label>Ihre Nachricht</label>
<textarea name="additional_information" placeholder="Welchen Service wünschen Sie? Wie sollen wir in Kontakt treten?" class="form-control" required rows="8"></textarea>
</div>
<div class="form-group" align="center">
<input type="submit" name="submit" value="Senden" class="btn btn-lg btn-success"/>
</div>
</form>
有个include_once('mail.php');在 index.php 当然,表格所在的位置。
mail.php 看起来像这样:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// HIDE ALL ERRORS
//error_reporting(0);
//ini_set('display_errors', 0);
$message = '';
if ( isset( $_POST['submit'] ) ) {
if ( isset( $_FILES['resume']['name'] ) && $_FILES['resume']['name'] != "" ) {
$path = 'upload/' . $_FILES['resume']['name'];
//print_r($path);
print_r( $_FILES );
move_uploaded_file( $_FILES["resume"]["tmp_name"], $path );
} else
$_FILES = NULL;
$message = '
<h3 align="center">Applicant Details</h3>
<table border="1" width="100%" cellpadding="5" cellspacing="5">
<tr>
<td width="30%">Name</td>
<td width="70%">' . $_POST["name"] . '</td>
</tr>
<tr>
<td width="30%">Email Address</td>
<td width="70%">' . $_POST["email"] . '</td>
</tr>
<tr>
<td width="30%">Phone Number</td>
<td width="70%">' . $_POST["mobile"] . '</td>
</tr>
<tr>
<td width="30%">Additional Information</td>
<td width="70%">' . $_POST["additional_information"] . '</td>
</tr>
</table>
';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/autoload.php';
$mail = new PHPMailer( true );
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
// ADD YOUR DETAILS HERE
//$mail->Host = 'smtp.gmail.com'; //Sets the SMTP hosts of your Email hosting
$mail->Host = 'smtp.iway.ch '; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = '587'; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication.
$mail->Username = 'email@email.com'; //Sets SMTP username
$mail->Password = 'example'; //Sets SMTP password
$mail->SMTPSecure = 'tls'; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->setFrom( 'email@email.com', 'example' ); //Sets the From email address for the message
$mail->addAddress( 'example@server.com' );
$mail->SMTPDebug = 0;
$mail->WordWrap = 50;
$mail->IsHTML( true ); //Sets message type to HTML
if ( isset( $_FILES['resume']['name'] ) && $_FILES['resume']['name'] != "" ) {
$mail->AddAttachment( $path ); //Adds an attachment from a path on the filesystem
}
$mail->Subject = 'Emaple Mail'; //Sets the Subject of the message
$mail->Body = $message; //An HTML or plain text message body
try {
$mail->send();
header( "Refresh:3; url=index.php" );
exit();
} catch (phpmailerException $e) {
echo $e->errorMessage();
echo $e->getMessage();
}
}
?>
电子邮件名称和密码是故意更改的。
我真的束手无策。这是我的第一个 Hompeage,其他一切都很好。为什么它在 5 分钟后发送电子邮件,但显示 503 而不是 index.php?
谢谢。
我认为您应该将 SMTP port 和 SMTP Secure 更改为:
$mail->Port = '465';
$mail->SMTPSecure = 'ssl';
所以我已经尝试了两天来摆脱这个问题。 如前所述,该代码在我的 xampp apache 本地主机上运行良好。电子邮件立即发送。 但是,在我拥有的域上,一旦我按下提交,它就会加载和加载,并且在 5 分钟左右后超时,或者更确切地说是“503 服务不可用”。 我检查了我的本地 PHP 错误日志,一切正常。 不过我无法访问服务器上的错误日志。
表单代码如下:
<div class="form-group">
<label>Ihr Name</label>
<input type="text" name="name" placeholder="Vorname Nachname" class="form-control" />
</div>
<div class="form-group">
<label>Ihre E-Mail Address</label>
<input type="email" name="email" class="form-control" placeholder="IhreEmail@server.com" />
</div>
<div class="col-md-6">
<div class="form-group">
<label>Ihre Nummer</label>
<input type="text" name="mobile" placeholder="Ihre Mobile 079 *** ** **" class="form-control" required/>
</div>
<hr/>
<div class="form-group">
<label><i class="far fa-file"></i>Ihr Dokument für die Übersetzung</label>
<input type="file" name="resume" accept=".doc,.docx,.pdf,.jpg,.bmp"/>
</div>
</div>
<div class="form-group">
<label>Ihre Nachricht</label>
<textarea name="additional_information" placeholder="Welchen Service wünschen Sie? Wie sollen wir in Kontakt treten?" class="form-control" required rows="8"></textarea>
</div>
<div class="form-group" align="center">
<input type="submit" name="submit" value="Senden" class="btn btn-lg btn-success"/>
</div>
</form>
有个include_once('mail.php');在 index.php 当然,表格所在的位置。 mail.php 看起来像这样:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// HIDE ALL ERRORS
//error_reporting(0);
//ini_set('display_errors', 0);
$message = '';
if ( isset( $_POST['submit'] ) ) {
if ( isset( $_FILES['resume']['name'] ) && $_FILES['resume']['name'] != "" ) {
$path = 'upload/' . $_FILES['resume']['name'];
//print_r($path);
print_r( $_FILES );
move_uploaded_file( $_FILES["resume"]["tmp_name"], $path );
} else
$_FILES = NULL;
$message = '
<h3 align="center">Applicant Details</h3>
<table border="1" width="100%" cellpadding="5" cellspacing="5">
<tr>
<td width="30%">Name</td>
<td width="70%">' . $_POST["name"] . '</td>
</tr>
<tr>
<td width="30%">Email Address</td>
<td width="70%">' . $_POST["email"] . '</td>
</tr>
<tr>
<td width="30%">Phone Number</td>
<td width="70%">' . $_POST["mobile"] . '</td>
</tr>
<tr>
<td width="30%">Additional Information</td>
<td width="70%">' . $_POST["additional_information"] . '</td>
</tr>
</table>
';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/autoload.php';
$mail = new PHPMailer( true );
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
// ADD YOUR DETAILS HERE
//$mail->Host = 'smtp.gmail.com'; //Sets the SMTP hosts of your Email hosting
$mail->Host = 'smtp.iway.ch '; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = '587'; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication.
$mail->Username = 'email@email.com'; //Sets SMTP username
$mail->Password = 'example'; //Sets SMTP password
$mail->SMTPSecure = 'tls'; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->setFrom( 'email@email.com', 'example' ); //Sets the From email address for the message
$mail->addAddress( 'example@server.com' );
$mail->SMTPDebug = 0;
$mail->WordWrap = 50;
$mail->IsHTML( true ); //Sets message type to HTML
if ( isset( $_FILES['resume']['name'] ) && $_FILES['resume']['name'] != "" ) {
$mail->AddAttachment( $path ); //Adds an attachment from a path on the filesystem
}
$mail->Subject = 'Emaple Mail'; //Sets the Subject of the message
$mail->Body = $message; //An HTML or plain text message body
try {
$mail->send();
header( "Refresh:3; url=index.php" );
exit();
} catch (phpmailerException $e) {
echo $e->errorMessage();
echo $e->getMessage();
}
}
?>
电子邮件名称和密码是故意更改的。 我真的束手无策。这是我的第一个 Hompeage,其他一切都很好。为什么它在 5 分钟后发送电子邮件,但显示 503 而不是 index.php? 谢谢。
我认为您应该将 SMTP port 和 SMTP Secure 更改为:
$mail->Port = '465';
$mail->SMTPSecure = 'ssl';