Jump to content

I AM ALMOST THERE, is all i can say.

Hours I've spent on trying to get this to work. Hours. If those hours were to be added it, it'd be a couple days.

 

Now all I need to figure out is how to send the email and information that the user puts into the form to any given email that I put into the code.

I've been researching, and I've heard something about how GoDaddy provides a service that can do this? I am currently paying for GoDaddy.

 

What do I do?

 

Here is the code that I have:

Spoiler

<?php
if(isset($_POST['email'])){

    // Here is the email to information    
    $email_to = "myemail@mydomain.com";
    $email_subject = "Ultra Media Contact Form Filled Out";
    $email_from = "Ultra Media Forms";
    
    // error code
    
    function died($error){
            echo "We are sorry, but there were error(s) found with the form you submitted.";
            echo "These errors appear below.</br><br/>";
            echo $error. "<br/><br/>";
            echo "Please go back and fix these errors.<br/>";
            die();
    }
    $first = $_POST['first'];
    $first = $_POST['last'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $emailmessage = $_POST['message'];
    
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+/.[A-Za-z] {2,4}$/';
    if(!preg_match($email_exp, $email)) {
        $error_message .= 'The  email address you have entered does not appear to be valid.';
    }
    
    function clean_string($string){
            $bad = array("content-type", "bcc:", "to:", "cc:", "href");
            return str_replace($bad, "", $string);
    }
    
    $email_message .= "First:" . clean_string($first) . "/n";
    $email_message .= "Last:" . clean_string($last) . "/n";
    $email_message .= "Email:" . clean_string($email) . "/n";
    $email_message .= "Subject:" . clean_string($subject) . "/n";
    $email_message .= "Message:" . clean_string($emailmessage) . "/n";

    $headers = 'From: ' .$email_From. "/r/n". 'Reply-To:' .
    $email. "/r/n" .
        'X-Mailer: PHP/' . phpversion();
        @mail($email_to, $email_subject, $email_message, $headers);
}
        ?>

Thank you for contacting Ultra Media. We will contact you shortly. <br/><br/>
Please click <a href="index.html">here</a> to go back to our home page.
 

 

Link to comment
https://linustechtips.com/topic/593198-php-email-form-final-stage-help/
Share on other sites

Link to post
Share on other sites

Hello and welcome to the wonderful world that is sending mails with php! (insert sarcasm face here)

If I were you I'd not use the built in mail support from PHP. But instead I'd choose for using a library that takes care of things for you. SwiftMailer is a good example of one such library.

 

Find it Here.

 

The fun thing about SwiftMailer is that it allows you to tap into email service providers like Gmail to send the mails for you.

 

You can find more up to date documentation on using the library by searching for it on google. As I see you're trying to do mail for a company

 

PS: that email regex is terrible.

use this instead

/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD

Souce: http://emailregex.com/

CPU: Intel Core i5 4690K @ 4.6Ghz CPU Cooler: Noctua NH-D15 GPU: GTX 1070 TI RAM: Crucial Ballistix Tactical 16GB (4x4) Mobo: ASUS Z97-PRO(Wi-Fi ac) PSU: Corsair RM Series RM750 Case: Fractal Design Define R4 no window

Link to post
Share on other sites

Many people argue a long and complicated regex is terrible for email, mostly they use is a really simple one with a email validation so you know the email is correct.

Not sure if they did update the regex but you see many people complaining about it with the newer and longer domain extensions.

 

Like one of the first posts say  test@test.yoga  doesnt work.

Quote or mention me if not feel ignored 

Link to post
Share on other sites

I simply used PHPMail and followed this tutorial: 

 I'd recommend it as the guy helps explain what a lot of the functions are doing and walks you through the entire process.

Gaming Rig - Excalibur - CPU: i5 6600k @ 4.1GHz, CPU Cooler: Hyper 212 Evo, Mobo: MSI Gaming M3 RAM: 16GB Corsair @2400MHz, GPU: EVGA 1060, Case: NZXT Phantom Full Tower (Red)

My Virtualization Server - Dell R710: 2x X5570s @ 2.93GHz with 32GB DDR3 RAM [Web Server, OSX, Plex, Reverse Proxy]

I love computers, gaming, coding, and photography! Be sure to quote me so I can respond to your post!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×