0

My code below not sending email to the mailing server to subscribe to a mailing list, I am confused as to why it is not working.Displays thank you webpage once submitted,not getting any response sent from list handler, if entered manually in email i get a response...

<?php

//thanku webpage routine
if (isset($_POST['submit']))
   {  
    ?>
<script type="text/javascript">
window.location = "http://www.thankyou web url here ";
</script> 

<?php
}
if(isset($_POST['email'])) {
$to = "email address here" ;
$message = "SUBSCRIBE list name" ;
$subject = " ";
$email = $_POST["email"] ;
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

  }
?>

<form class="rform" method="post" action="https://webform web url"> 

<fieldset><legend><strong>Signup</strong></legend>
<h4> mailing list text here:</h4>

<p><label for="email">Email address:</label> <input title="email address."    name="email" type='email' pattern=".+(@tvs.ac.uk)|.+(@tvsa.ac.uk)|.+ (@research.gla.ac.uk)" required />

</p>
 <input style="float: right;" type="submit" name="submit" value="Subscribe"   /> </fieldset> </form>
user3723480
  • 83
  • 2
  • 9
  • do you get any error or why do you know that it does not try to send an email? – Ann-Sophie Angermüller Mar 14 '17 at 16:18
  • 1
    Well you are saying if(isset($_POST['submit'])), then redirect to other page ! So when the form is submitted, you will be redirected to another page before running other part of the code ! –  Mar 14 '17 at 16:20
  • hi ann, thanks for quick response, the list handler usually send an email , in my case i dont get one !..thanks..singhy – user3723480 Mar 14 '17 at 16:24
  • hi sohey, yes fisrt link is the thankyou webpage and the second link is where the web form (short one exists)...thanks for help...singhy – user3723480 Mar 14 '17 at 16:25
  • hi ann, i dont get any errors but i can not check at server end !...thanks...singhy – user3723480 Mar 14 '17 at 19:47
  • hi fred, thanks i had searched earlier prior to posting this question was not aware i had posted a duplicate !, apologises...singhy – user3723480 Mar 14 '17 at 19:59
  • Hi all, problem solved, the solution was to view the messages at server end which had the key solution.. my code was right it was the staging server which neede tweaking, thanks again for all the possible solutions given to me...thanks...singhy – user3723480 Mar 15 '17 at 11:57

2 Answers2

0

To redirect javascript is not needed. Also redirection should be done once the needed logic is done. Try the below script

<?
if(isset($_POST['email'])) {
   $to = "email address here" ;
   $message = "SUBSCRIBE list name" ;
   $subject = " ";
   $email = $_POST["email"] ;
   $headers = 'From: '.$email."\r\n".
   'Reply-To: '.$email."\r\n" .
   'X-Mailer: PHP/' . phpversion();
   mail($to, $subject, $message, $headers);

   header('location:http://www.thankyou web url here');
}
?>
siddiq
  • 1,693
  • 3
  • 17
  • 44
  • hi siddiq, thanks for the code snippet but i do not get the response from the listhandler e.g. if i manually send the email to with blank subject and put the subscribe list name in the body of the message i get the response fine.... i am wondering where the problem could be ...i have the identical code working on a different list which responses just fine...thanks again for your valuable time...singhy – user3723480 Mar 14 '17 at 19:42
0
  • Check your server's SMTP settings. Is your SMTP activated in your php.ini ?
    • Try to check your server logs. It may give you more information

For example, with a try on a blank server i had :

PHP Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in [...]index.php on line 20, referer: http://localhost/

Loïc
  • 131
  • 5
  • hi loic thanks for the suggestion will try when i go in the morning will ask server folk...to make sure there are no errors etc...thanks singhy – user3723480 Mar 14 '17 at 19:49
  • As mentioned by @Fred-ii, read this question : http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail?noredirect=1&lq=1 – Loïc Mar 15 '17 at 08:45
  • hi loic, thanks will do.. – user3723480 Mar 15 '17 at 09:04