Jump to content
Sigmahokies

PHP email

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

Share this post


Link to post
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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...