-1

Custom subscribe form gives terrible error.

Warning: Cannot modify header information - headers already sent by (output started at /customers/3/3/a/website.nl/httpd.www/aanmelden/contactengine.php:87) in /customers/3/3/a/website.nl/httpd.www/aanmelden/contactengine.php on line 89

The contact engine will not send the form, it is displaying this error. And pop up the JavaScript error that the message not will be send.

Anyone any suggestions?

catch (Exception $e) { print "window.alert('Bericht is niet verzonden')"; print "http://www.website.com/aanmelden/index.php\">"; header('Location: http://www.website.com/aanmelden/index.php'); } Warning: Cannot modify header information - headers already sent by (output started at/... contactengine.php:82) in /customers/3/3/a/.... online 84 [enter image description here][1]

contactengine.php

<?php
  use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\SMTP;
  use PHPMailer\PHPMailer\Exception;
  ini_set('display_errors', '1');
  require('src/PHPMailer/vendor/autoload.php');

  $mail = new PHPMailer(true);
  try {
    $mail->IsSMTP();  // Telling the class to use SMTP
    $mail->SMTPDebug = 0; // shows debugging
    $mail->Host     = "mailout.one.com"; // SMTP server
    $mail->SMTPAuth = true;
    $mail->Username = "--"; // "The account"
    $mail->Password = "--"; // "The password"
    $mail->SMTPSecure = "false";
    $mail->Port = 25; // "The port"


// - Mailer: SMTP Mail Function 
// - Mail from: [active account in your domain]
// - From Name: [your name]
// - Sendmail Path   /usr/sbin/sendmail 
// - SMTP Authentication:  True  
// - SMTP Username: [Same as the Mail from stated above]
// - SMTP Password: [password of the above username]
// - SMTP Host: mailout.one.com
// - SMTP Security: [none]
// - Port 25

    $mail->setFrom('info@email.com', 'Buisiness name');
    $mail->addAddress('info@email.com'); // recipient address
    $mail->addReplyTo('info@email.com');

    $mail->isHTML(true);
    $mail->Subject = 'Nieuwe aanmelding';

    $mail->Body = "";
    $mail->Body .= "<h3>Nieuwe aanmelding</3>";
    $mail->Body .= "<h5>Nieuwe aanmelding</h5>";
    $mail->Body .= Trim(stripslashes($_POST['aanhef']));
    $mail->Body .= " ";
    $mail->Body .= Trim(stripslashes($_POST['Name']));
    $mail->Body .= Trim(stripslashes($_POST['Surname']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Geboorteland</h5>";
    $mail->Body .= Trim(stripslashes($_POST['geboorteland']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>BSN</h5>";
    $mail->Body .= Trim(stripslashes($_POST['bsn']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Geboortedatum</h5>";
    $mail->Body .= Trim(stripslashes($_POST['date']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Aankomst</h5>";
    $mail->Body .= Trim(stripslashes($_POST['aankomst']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Woonadres</h5>";
    $mail->Body .= Trim(stripslashes($_POST['woonadres']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Postcode</h5>";
    $mail->Body .= Trim(stripslashes($_POST['postcode']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Woonplaats</h5>";
    $mail->Body .= Trim(stripslashes($_POST['woonplaats']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Telefoonnummer</h5>";
    $mail->Body .= Trim(stripslashes($_POST['telefoon']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Aanmelding voor locatie</h5>";
    $mail->Body .= Trim(stripslashes($_POST['locatie']));
    $mail->Body .= "<br /><br />";
    $mail->Body .= "<h5>Inschrijving</h5>";
    $mail->Body .= Trim(stripslashes($_POST['inschrijven']));

    $mail->send();
    print "<script language=JavaScript>window.alert('Bericht is verzonden')</script>";
    print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.website.com/aanmelden/index.php\">";
    header('Location: index.php');
  } catch (Exception $e) {
    print "<script language=JavaScript>window.alert('Bericht is niet verzonden')</script>";
    print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.website.com/aanmelden/index.php\">";
    header('Location: http://www.website.com/aanmelden/index.php');
  }

?>

aanmelden.php

<?php include_once ('../inc/header.inc.php'); ?>


<form method="post" action="contactengine.php">

                                                    <div class="container">
                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0">
                                                                <p>Aanhef<br /> Preamble // الى حضرة<br/>
                                                                </div>
                                                            <div class="col-md-6 col-md-offset-0">
                                                                <ul class=" style-5 clearfix"><li>
                                                                    <select name="aanhef">
                                                                        <option value="Dhr">Dhr. | Mr.  | السيد</option>
                                                                    <option value="Mevr">Mevr. | Mrs. | السيدة</option>
                                                                </select>
                                                                </ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Voornaam<br/>First name // الإسم الشخصي<br/></div>
                                                            <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input type="text" name="Name" id="Name" cols="10" class="textbox" required /><br />
                                                            </li></ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Achternaam<br/>Surname // الاسم العائلي<br/></div>
                                                            <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input type="text" name="Surname" id="Surname" cols="10" class="textbox" required /><br />
                                                            </li></ul></div>
                                                        </div>

                                                        <div class="row">
                                                        <div class="col-md-3 col-md-offset-0"><p>Geboorteland<br/>Country of Birth//  بلد الولادة<br/></div>
                                                        <div class="col-md-6 col-md-offset-0">
                                                        <ul class=" style-5 clearfix"><li>
                                                                <select name="geboorteland" id="geboorteland">
                                                                    <option value="0" label="Select a country … " selected="selected">Select a country … </option>
                                                                    <optgroup id="country-optgroup-Africa" label="Africa">
                                                                        <option value="Algeria" label="Algeria">Algeria</option>
                                                                        <option value="Angola" label="Angola">Angola</option>
                                                                        <option value="Benin" label="Benin">Benin</option>
                                                                        <option value="Botswana" label="Botswana">Botswana</option>
                                                                        <option value="Burkina Faso" label="Burkina Faso">Burkina Faso</option>
                                                                        <option value="Burundi" label="Burundi">Burundi</option>
                                                                        <option value="Cameroon" label="Cameroon">Cameroon</option>
                                                                        <option value="Cape Verde" label="Cape Verde">Cape Verde</option>
                                                                        <option value="Central African Republic" label="Central African Republic">Central African Republic</option>
                                                                        <option value="Chad" label="Chad">Chad</option>
                                                                        <option value="Comoros" label="≈">Comoros</option>
                                                                        <option value="Congo Brazzaville" label="Congo - Brazzaville">Congo - Brazzaville</option>
                                                                        <option value="Congo Kinshasa" label="Congo - Kinshasa">Congo - Kinshasa</option>
                                                                        <option value="Côte d’Ivoire" label="Côte d’Ivoire">Côte d’Ivoire</option>
                                                                        <option value="Djibouti" label="Djibouti">Djibouti</option>
                                                                        <option value="Egypt" label="Egypt">Egypt</option>
                                                                        <option value="Equatorial Guinea" label="Equatorial Guinea">Equatorial Guinea</option>
                                                                        <option value="Eritrea" label="Eritrea">Eritrea</option>
                                                                        <option value="Ethiopia" label="Ethiopia">Ethiopia</option>
                                                                        <option value="Gabon" label="Gabon">Gabon</option>
                                                                        <option value="Gambia" label="Gambia">Gambia</option>
                                                                        <option value="Ghana" label="Ghana">Ghana</option>
                                                                        <option value="Guinea" label="Guinea">Guinea</option>
                                                                        <option value="Guinea-Bissau" label="Guinea-Bissau">Guinea-Bissau</option>
                                                                        <option value="Kenya" label="Kenya">Kenya</option>
                                                                        <option value="Lesotho" label="Lesotho">Lesotho</option>
                                                                        <option value="Liberia" label="Liberia">Liberia</option>
                                                                        <option value="Libya" label="Libya">Libya</option>
                                                                        <option value="Madagascar" label="Madagascar">Madagascar</option>
                                                                        <option value="Malawi" label="Malawi">Malawi</option>
                                                                        <option value="Mali" label="Mali">Mali</option>
                                                                        <option value="Mauritania" label="Mauritania">Mauritania</option>
                                                                        <option value="Mauritius" label="Mauritius">Mauritius</option>
                                                                        <option value="Mayotte" label="Mayotte">Mayotte</option>
                                                                        <option value="Morocco" label="Morocco">Morocco</option>
                                                                        <option value="Mozambique" label="Mozambique">Mozambique</option>
                                                                        <option value="Namibia" label="Namibia">Namibia</option>
                                                                        <option value="Niger" label="Niger">Niger</option>
                                                                        <option value="Nigeria" label="Nigeria">Nigeria</option>
                                                                        <option value="Rwanda" label="Rwanda">Rwanda</option>
                                                                        <option value="Réunion" label="Réunion">Réunion</option>
                                                                        <option value="Saint Helena" label="Saint Helena">Saint Helena</option>
                                                                        <option value="Senegal" label="Senegal">Senegal</option>
                                                                        <option value="Seychelles" label="Seychelles">Seychelles</option>
                                                                        <option value="Sierra Leone" label="Sierra Leone">Sierra Leone</option>
                                                                        <option value="Somalia" label="Somalia">Somalia</option>
                                                                        <option value="South Africa" label="South Africa">South Africa</option>
                                                                        <option value="Sudan" label="Sudan">Sudan</option>
                                                                        <option value="Swaziland" label="Swaziland">Swaziland</option>
                                                                        <option value="São Tomé and Príncipe" label="São Tomé and Príncipe">São Tomé and Príncipe</option>
                                                                        <option value="Tanzania" label="Tanzania">Tanzania</option>
                                                                        <option value="Togo" label="Togo">Togo</option>
                                                                        <option value="Tunisia" label="Tunisia">Tunisia</option>
                                                                        <option value="Uganda" label="Uganda">Uganda</option>
                                                                        <option value="Western Sahara" label="Western Sahara">Western Sahara</option>
                                                                        <option value="Zambia" label="Zambia">Zambia</option>
                                                                        <option value="Zimbabwe" label="Zimbabwe">Zimbabwe</option>
                                                                    </optgroup>
                                                                    <optgroup id="country-optgroup-Americas" label="Americas">
                                                                        <option value="Anguilla" label="Anguilla">Anguilla</option>
                                                                        <option value="Antigua and Barbuda" label="Antigua and Barbuda">Antigua and Barbuda</option>
                                                                        <option value="Argentina" label="Argentina">Argentina</option>
                                                                        <option value="Aruba" label="Aruba">Aruba</option>
                                                                        <option value="Bahamas" label="Bahamas">Bahamas</option>
                                                                        <option value="Barbados" label="Barbados">Barbados</option>             <option value="Austria" label="Austria">Austria</option>
                                                                        <option value="Belarus" label="Belarus">Belarus</option>
                                                                        <option value="Belgium" label="Belgium">Belgium</option>
                                                                        <option value="Bosnia and Herzegovina" label="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
                                                                        <option value="Bulgaria" label="Bulgaria">Bulgaria</option>
                                                                        <option value="Croatia" label="Croatia">Croatia</option>
                                                                        <option value="Cyprus" label="Cyprus">Cyprus</option>
                                                                        <option value="Tuvalu" label="Tuvalu">Tuvalu</option>
                                                                        <option value="U.S. Minor Outlying Islands" label="U.S. Minor Outlying Islands">U.S. Minor Outlying Islands</option>
                                                                        <option value="Vanuatu" label="Vanuatu">Vanuatu</option>
                                                                        <option value="Wallis and Futuna" label="Wallis and Futuna">Wallis and Futuna</option>
                                                                    </optgroup>
                                                                </select>
                                                            </ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>BSN<br/>Fiscal number //  رقم الخدمة المدنية   <br/></div>
                                                                    <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input type="text" name="bsn" id="bsn" class="textbox" required /><br />
                                                                    </li></ul></div>
                                                        </div>

                                  <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Aanmelden voor locatie<br/> //  Registration for location<br/>//رقم الخدمة المدنية <br/></div>
                                                                    <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>

                                        <select name="locatie" id="locatie">
                                          <option value="0" label="Select a location … " selected="selected">Select a location … </option>
                                          <option value="Breda">Breda</option>
                                          <option value="Rotterdam">Rotterdam</option>
                                          <option value="Hellevoetsluis">Hellevoetsluis</option><br />
                                          <option value="Leiden">Leiden</option><br />
                                      </select>
                                                                    </li></ul></div>
                                                        </div>


                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Geboortedatum<br/>Date of birth // تاريخ الميلاد<br/></div>
                                                            <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input id="date" name="date" placeholder="MM/DD/YYYY" type="text" required/><br />
                                                            </li></ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Datum van aankomst in Nederland<br/>Date of arrival in the Netherlands //  تاريخ الوصول إلى هولندا<br/></div>
                                                            <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input id="aankomst" name="aankomst" placeholder="MM/DD/YYYY" type="text" required/><br />
                                                            </li></ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Woonadres<br/>Adress // العنوان<br/></div>
                                                            <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input id="woonadres" name="woonadres" type="text" required/><br />
                                                            </li></ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Postcode<br/>Postal code // الرمز<br/></div>
                                                            <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input id="postcode" name="postcode" type="text" required/><br />
                                                            </li></ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Woonplaats<br/>Place // مكان الإقامة<br/></div>
                                                            <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input id="woonplaats" name="woonplaats" type="text" required/><br />
                                                            </li></ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0"><p>Telefoonnummer<br/>Telephone //الهاتف<br/></div>
                                                            <div class="col-md-6 col-md-offset-0"><ul class=" style-5 clearfix"><li>
                                                                    <input id="telefoon" name="telefoon" type="text" maxlength="10" required/><br />
                                                            </li></ul></div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-12 col-md-offset-0">&nbsp;
                                                            <div class="col-md-12 col-md-offset-0"><ul class=" style-5 clearfix"><li>

                                                                </li></ul></div>
                                                        </div>
                                                    </div>

                                                        <div class="row">
                                                            <div class="col-md-3 col-md-offset-0">&nbsp;
                                                            <div class="col-md-6 col-md-offset-0">
                                                                    <input name="submit" class="btn" type="submit" value="Verstuur" /><br class="clear" />
                                                                    <br />
                                                                </div>
                                                        </div>
                                                    </div>


                                                                  </form>




<?php include_once ('../inc/footer.inc.php'); ?>
Niels
  • 3
  • 5

1 Answers1

0

I don't know the exact reason why header issue is coming but you can resolve it in the below way by using window.location of JavaScript instead of header of PHP for redirects.

Replace

header('Location: index.php');

With

echo("<script>window.location='index.php';</script>");

And Replace

header('Location: http://www.website.com/aanmelden/index.php');

With

echo("<script>window.location='http://www.website.com/aanmelden/index.php';</script>");

Hope it helps!

Amit Gupta
  • 2,771
  • 2
  • 17
  • 31
  • Big thanks for your reply. But it doesn't solve the issue. It is not showing the location error anymore. But it show the "Bericht is niet verzonden" message that means The message can't be send. There is no php error popping up. – Niels Dec 16 '17 at 11:04
  • You are welcome. Issue resolved or not? – Amit Gupta Dec 16 '17 at 11:05
  • Check the edited comment.:) – Niels Dec 16 '17 at 11:09
  • This is the another error. Earlier header error is resolved. This error related to emails. – Amit Gupta Dec 16 '17 at 11:10
  • I will check your code again to resolve this one. – Amit Gupta Dec 16 '17 at 11:10
  • Your emails are working properly in your server? – Amit Gupta Dec 16 '17 at 11:14
  • Have you used PHPMailer in some other places as well? – Amit Gupta Dec 16 '17 at 11:14
  • Issue now related with email only. It comes in else condition. – Amit Gupta Dec 16 '17 at 11:15
  • Yes sir. What is the best way to solve it. Repost another question and title or with this background information? The script has worked perfectly a month, I really don't know what has changed. – Niels Dec 16 '17 at 11:15
  • I think repost another question so that you can also get view from other person as well. But please accept this one. – Amit Gupta Dec 16 '17 at 11:16
  • Also make sure that emails are working in your server. You can also try simple PHP mail() function to test. – Amit Gupta Dec 16 '17 at 11:18
  • first test your emails with mail("yourid@gmail.com","test","testing","From: anyid@gmail.com"); – Amit Gupta Dec 16 '17 at 11:19
  • Thanks for your view because your open my mind and let me check if al the email settings are correct. There was a wrong password used. Haha. So now it is fixed completely. – Niels Dec 16 '17 at 11:24
  • Oh that's nice, Please don't forget to accept my answer dear friend :) Happy Coding! – Amit Gupta Dec 16 '17 at 11:26
  • How can I accept it. This is my first experience on this site. – Niels Dec 16 '17 at 11:31
  • To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in. https://i.stack.imgur.com/uqJeW.png – Amit Gupta Dec 16 '17 at 11:32
  • Thanks a lot dude :) You are welcome to contact me again if you find any other issue. You can even add me at https://facebook.com/amitg100 I will be really happy to help you. – Amit Gupta Dec 16 '17 at 11:34