Jump to content

Recommended Posts

Hello All

 

I've had this script working on my website for a couple of year but the server has been upgraded to PHP5 and I can on longer send emails.

Any body got any idea why this should be

 

This code (below ) used as a test says the email has been sent but nothing appears, the SMTP value on the PHP info is localhost

<?php

//phpinfo();

 

//define the receiver of the email

$to = 'myemail@gmail.com';

//define the subject of the email

$subject = 'Test email';

//define the message to be sent. Each line should be separated with \n

$message = "Hello World!\n\nThis is my first mail.";

//define the headers we want passed. Note that they are separated with \r\n

$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";

//send the email

$mail_sent = @mail( $to, $subject, $message, $headers );

//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"

echo $mail_sent ? "Mail sent" : "Mail failed";

?>

 

Here is the code from my page

 

 

<?php # Script 3.13 - register.php

if (isset($_POST['submit'])) { // Handle the form.

$message2 = NULL; //empty new variable.

$subject = 'Email From Gallery Website'; // Subject.

$emailadd = 'myemail@gmail.com';//The email will be sent here.

$url = 'thankyou.php'; 

// Check for a name.

if (strlen($_POST['name']) > 0) {$name = TRUE;}

else {$name = FALSE;$message2 .= '<p>You forgot to enter your name!</p>';}

// Check for a username.

if (strlen($_POST['email']) > 0) {$email = TRUE;}

else {$email = FALSE;$message2 .= '<p>You forgot to enter your user name!</p>';}

// Check for an email address.

if (strlen($_POST['message']) > 0) {$message = TRUE;}

else {$message = FALSE;$message2 .= '<p>You forgot to enter your email address!</p>';}

if ($name && $email && $message) { // If everything's okay.

$messageproper =

"Name of sender: {$_POST['name']}\n" .

"Email of sender: {$_POST['email']}\n" .

"Message -------------\n\n" .

$_POST['message'] .

"\n\n------------------" ;

mail($emailadd, $subject, $messageproper, "From: {$_POST['email']}");

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

} else {

$message2 .= '<p>Please try again.</p>';}}?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<?php if (isset($message2)) {echo '<div id="cnt-mis">', $message2, '</div>';}?>

<div class="cnt-inn"><fieldset><legend>Your Details and Message</legend>

<div><label for="name">Name:</label><input type="text" name="name" id="name" tabindex="1" /></div>

<div><label for="email">Email Address:</label><input type="text" name="email" id="email" tabindex="2" /></div>

<div><label for="message">Message:</label><textarea id="message" name="message" tabindex="2"></textarea></div>

<input type="submit" id="submit" name="submit" value="Submit" tabindex="4" /></fieldset></div>

</form>

 

Any help appreciated

 

Jason

 

Link to comment
https://forums.phpfreaks.com/topic/121835-php-mail-suddenly-not-working/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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