Jump to content

PHP email


Sigmahokies

Recommended Posts

Hi everyone, Can anyone help me underatdn why my email in php didn't work. I set up the email form in web, seem it didn't send at all. I put boolean with email, then I tested to fill out text to send email, then it said it didn't send email at all.

What did I do wrong?

	<?php
$error = "";
	if($_SERVER['REQUEST_METHOD'] == "POST") {
    if (empty($_POST['email'])) {
    $error = "<tr><td colspan='2'>E-mail is required</td></tr>";
    } elseif (empty($_POST['FirstName'])) {
    $error = "<tr><td colspan='2'>First Name is required</td></tr>";
    } elseif (empty($_POST['LastName'])) {
    $error = "<tr><td colspan='2'>Last Name is required</td></tr>";
    } elseif (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    $error = "<tr><td colspan='2'>Invalid e-mail format</td></tr>";
    } else {
        
        $first = $_POST['FirstName'];
        $last = $_POST['LastName'];
        $email = $_POST['email'];
        $comment = $_POST['comment'];
        $title = $_POST['Title'];
	        $emailGary = "XXXX@gmail.com";
        
        if(mail($emailGary, $title, $comment)) {
        $sent = "<tr><td colspan='2'>E-mail has been sent</td></tr>";
        } else {
        $sent = "<tr><td colspan='2'>E-mail has not sent</td></tr>";
    }
}
}
	?>
<body class="background">
    <h5><a href="#garydtaylor">XXXX</a></h5>
<div class="w3-row">
    <div class="w3-col" style="width:300px; text-align: left; padding-left: 50px;"><p>Hello</p></div>
    <div class="w3-rest w3-round" style="text-align: left; padding-left: 50px;"><p>Hello</p>
    <form action="resume.php" method="post">
        <table cellpadding="5">
            <tr><td>* First Name:</td><td><input type="text" name="FirstName"></td></tr>
            <tr><td>* Last Name:</td><td><input type="text" name="LastName"></td></tr>
            <tr><td>* Title:</td><td><input type="text" name="Title"></td></tr>
            <tr><td>* Email:</td><td><input type="text" name="email"></td></tr>
            <tr><td valign="top">* Comment:</td><td><textarea maxlength="5000" cols="18" rows="6" type="text" name="comment"></textarea></td></tr>
            <tr></tr><td></td><td><input type="submit" name="submit" class="w3-round" style="background: maroon; color: white; height: 25px; width: 175px;" value="E-mail to Gary Taylor"></td>
            <?php echo $error ?>
            <?php echo $sent ?>
        </table>
    </form>
    </div>
</div>
</div>
</body>
</html>
	

Can you help me? Of course, i will use CSS to make it decoration as style, but I want to make sure it works.

Thanks,

Gary

Edited by Sigmahokies
Link to comment
Share on other sites

  • 2 weeks later...

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
×
×
  • Create New...