Home > Software design >  PHPMailer: Working on localhost, stuck after clicking "submit" button on the domain, gives
PHPMailer: Working on localhost, stuck after clicking "submit" button on the domain, gives

Time:03-14

So I've been trying now for two days to get rid of this problem. As mentioned, the code works perfectly fine on my xampp apache localhost. The Email is send immediately. However, on the domain which I have, once I press submit, it just loads and loads, and after 5mins or so gets a timeout, or rather a "503 Servive unavailable". I've checked my local PHP error log, everything is fine. I don't have access to the error log on the server though.

Here is the code for the form:

<div >
    <label>Ihr Name</label>
    <input type="text" name="name" placeholder="Vorname Nachname"   />
</div>
<div >
    <label>Ihre E-Mail Address</label>
    <input type="email" name="email"  placeholder="[email protected]"  />
</div>
<div >

    <div >
        <label>Ihre Nummer</label>
        <input type="text" name="mobile" placeholder="Ihre Mobile 079 *** ** **"  required/>
    </div>
    <hr/>
    <div >
        <label><i ></i>Ihr Dokument für die Übersetzung</label>
        <input type="file" name="resume" accept=".doc,.docx,.pdf,.jpg,.bmp"/>
    </div>
</div>
<div >
    <label>Ihre Nachricht</label>
    <textarea name="additional_information" placeholder="Welchen Service wünschen Sie? Wie sollen wir in Kontakt treten?"  required rows="8"></textarea>
</div>
<div  align="center">
    <input type="submit" name="submit" value="Senden" />
</div>
</form>

There is a include_once('mail.php'); in the index.php of course, where the form is at. The mail.php looks like this:

<?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 protected]'; //Sets SMTP username
    $mail->Password = 'example'; //Sets SMTP password
    $mail->SMTPSecure = 'tls'; //Sets connection prefix. Options are "", "ssl" or "tls"

    $mail->setFrom( '[email protected]', 'example' ); //Sets the From email address for the message
    $mail->addAddress( '[email protected]' );
    $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();
    }

}

?>

The email name and PW are changed on purpose. I am really at my wits end. That's my first Hompeage, everything else works just fine. Why does it send the Email after 5mins, but shows 503 and not the index.php again? Thank you.

CodePudding user response:

I think that you should change SMTP port and SMTP Secure to:

$mail->Port = '465';
$mail->SMTPSecure = 'ssl';
  • Related