0

Been trying to get this working and sending to my email from the website but the emails aren't coming through.

It is probably something really easy. I also blocked my actual sending email (for both areas)

Thanks for any help!

My php code in index.php

<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
$mail_to = 'coverupemail@email.com';
$subject = 'Message from a portfolio visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message.');
        window.location = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email manually to coverupemail@email.com');
        window.location = 'index.html';
    </script>
<?php
}
?>

My HTML code linking to index.php

<form method="post" action="index.php">
    <p class="contact">
        <input type="text" name="name" id="name" value="" size="22" />
        <label for="name"><small>Name (required)</small></label>
    </p>
    <p class="contact">
         <input type="email" name="email" id="email" value="" size="22" />
         <label for="email"><small>Mail (required)</small></label>
    </p>
    <p class="contact">
        <textarea name="message" id="message" value="" rows="10"></textarea>
        <label for="message"><small>Message (required)</small></label>
    </p>
    <p class="contact">
        <input id="submit" name="submit" type="submit" value="Submit" />
        <input name="reset" type="reset" id="reset" tabindex="5" value="Reset Form" />
    </p>
</form>

1 Answers1

0

What is the $mail_status value ? Even if its "1" it does not guarantee the sending of mail :( it then depends upon the server PHP returns 1 the moment the message is handed over to the mail sending part of the server.

Cases 1 : if the script is running on server then try a sample code to verify that actually mail are been sent create a page mailtest.php with the following code

<?php mail("coverupemail@email.com","Test Msg","Hello this is just test message");?>

this will verify that yes its working.

Case 2 : if you are working on a localhost then u will have to have some SMTP server or mail server to make it easy you can use gmail to send via your localhost ( i did this i use my gmail account )

Also see this link Email sending

btw a. ini_set() i think is not used. b. also window.location = 'index.html'; will just navigate to the index page wat if the person navigates back ? the mail wud be sent again maybe... so i wud suggest to use

location.replace('index.html');

Thx

Community
  • 1
  • 1
Ahmad
  • 437
  • 1
  • 4
  • 12