Hai there,

I have doing php code for form data to be send to email.
But it is showing...

Your message could not be sent at this time. Please try again.

Here is my code for html form...

<body>

	<div id="emailform">
		<form action="email-thankyou.php" method="post" name="contactForm" onsubmit="return validateForm(this);">
			<p><strong>Name:</strong> <input name="name" type="text" size="40" /></p>
			<p><strong>Email:</strong> <input name="email" type="text" size="40" /></p>
			<p><strong>Message:</strong></p>
			<p><textarea name="message" rows="4" cols="50"></textarea></p>
			<div id="buttons"><input type="submit" value="Send Email">&nbsp;&nbsp;<input type="reset" value="Reset"></div>
		</form>
	</div>
				
</body>

Here is my code for php file....

<?php 
  
    // Grab the form vars 
    $email = (isset($_POST['email'])) ? $_POST['email'] : '' ; 
    $message = (isset($_POST['message'])) ? $_POST['message'] : '' ; 
    $name = (isset($_POST['name'])) ? $_POST['name'] : '' ; 
  
    // Check for email injection 
    if (has_emailheaders($email)) { 
        die("Possible email injection occuring"); 
    } 
  
    $sent = @mail("ssmeshack@gmail.com", "Subject of the email ", "Name: $name\n Email: $email\n\n $message", "From: $email"); 
  
        if ($sent ) {  
            echo "Thank you for your inquiry, Your message has been received. <br>We will get back to you as soon as we can.";  
        } else {  
            echo "Your message could not be sent at this time. Please try again.";  
        } 
function has_emailheaders($text) { 
    return preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i", $text); 
} 
?>

Is it because im using yahoomail or gmail as a receiver's email?
Please help me....
Im a newbie in php coding.

Regards,
Meshack

Are you sure, you can use the mail function?
some servers block it fort spam reasons.

Are you sure, you can use the mail function?
some servers block it fort spam reasons.

hai there,
thanks for the reply...
yes. it really dont the send the data to email...
how about if I use own email server... like company...
but i dont understand 1 thing....
what is mail function?

thanks

You are using a certain function called mail()

$sent = @mail(...)

This is a built-in function off php, but can be turned off, to check if it is turned off, do phpinfo() and check if it is enabled.
I don't know what the @ is doing in front of the mail, I just use it without...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.