Jump to content

I can't figure out what i'm doing wrong for the life of me (PHP/SMTP)


emcuriah
 Share

Recommended Posts

Hello, 

thanks for opening this first and foremost. So i've been designing a website for myself here . On the last page is a contact form that i've been trying to figure out. This was a html web template that i had purchased and replaced with my own info, pics etc. everything is fully functional but i cannot figure out how to set up my handler.php file to route the contact form back to my gmail. The only directions on the contact form was to "refer to handler.php". I have attached a copy of that file, I think i have filled out the information correctly but still has error submitting contact form after uploading to aws. I'm really new to html or php, just trying to self teach myself but i havent been able to solute it with any research i've been looking up. Any guidance or info to where i might be going left is beyond appreciated.

 

Bless,

-MC

------------

 

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'file:///SSD/Users/mc/Documents/sites/elements-mikael-modern-creative-cvresume-template-28H8B9D-R78y6RFN-06-06/Mikael HTML/php/PHPMailer-5.2.28/src/Exception.php';
require 'file:///SSD/Users/mc/Documents/sites/elements-mikael-modern-creative-cvresume-template-28H8B9D-R78y6RFN-06-06/Mikael HTML/php/PHPMailer-5.2.28/src/PHPMailer.php';
require 'file:///SSD/Users/mc/Documents/sites/elements-mikael-modern-creative-cvresume-template-28H8B9D-R78y6RFN-06-06/Mikael HTML/php/PHPMailer-5.2.28/src/SMTP.php';

$mail = new PHPMailer(true);
$mail_subject = 'Subject';
$mail_to_email = 'emcuriah@gmail.com'; // your email
$mail_to_name = 'Webmaster';

try {

    $mail_from_name = isset( $_POST['name'] ) ? $_POST['name'] : '';
    $mail_from_email = isset( $_POST['email'] ) ? $_POST['email'] : '';
    $mail_category = isset( $_POST['category'] ) ? $_POST['category'] : '';
    $mail_budget = isset( $_POST['budget'] ) ? $_POST['budget'] : '';
    $mail_message = isset( $_POST['message'] ) ? $_POST['message'] : '';

    // Server settings
    $mail->isSMTP(); // Send using SMTP
    $mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'emcuriah@gmail.com'; // SMTP username
    $mail->Password = '...'; // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
    $mail->Port = 465; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    $mail->setFrom($mail_to_email, $mail_to_name); // Your email
    $mail->addAddress($mail_from_email, $mail_from_name); // Add a recipient

    // for($ct=0; $ct<count($_FILES['file_attach']['tmp_name']); $ct++) {
    //     $mail->AddAttachment($_FILES['file_attach']['tmp_name'][$ct], $_FILES['file_attach']['name'][$ct]);
    // }

    // Content
    $mail->isHTML(true); // Set email format to HTML

    $mail->Subject = $mail_subject;
    $mail->Body = '
        <strong>Name:</strong> ' . $mail_from_name . '<br>
        <strong>Email:</strong> ' . $mail_from_email . '<br>
        <strong>Category:</strong> ' . $mail_category . '<br>
        <strong>Budget:</strong> ' . $mail_budget . '<br>
        <strong>Message:</strong> ' . $mail_message;

    $mail->Send();

    echo 'Message has been sent!';

} catch (Exception $e) {

    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";

}

 

Link to comment
Share on other sites

  • emcuriah changed the title to I can't figure out what i'm doing wrong for the life of me (PHP/SMTP)

These type of contact pages don't work very well for a number of reasons, most notably that  bots fill your inbox with spam.  

This particular script can also be exploited by anyone (and again mostly it will be bots) to send email from your account, via this line:

$mail->addAddress($mail_from_email, $mail_from_name); // Add a recipient

I can spam your form, put a bunch of porn site links in the body, and have my from address be some person I want to spam with those links, and your gmail will send them a copy of the email.  That line should be commented out at very least.

As Req already noted, we need some debugging information, because we have no idea at what point where the script fails.  

 

Link to comment
Share on other sites

Almost forgot to say that I edited your original post because it appeared to contain your actual gmail password.  I would change your gmail password ASAP if it actually was the real one.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.