• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

help with php code

New Here ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Hi,

I am a novice, but trying to learn and I am ask for some help if anyone can. I have created a site but it is not the final site, just a draft. www.railwaychaplain.net

I have created a page with a contact form www.railwaychaplain.net/contact.php

I have placed the code I have used below. every thing looks ok for a simple form, but no message is received when 'Submit' is selected.

Would anyone please be able to correct whatever it is I have done wrong?

Thank you for your help.

Kind regards, Liam

--------

<?php

/*subject for RailHope email*/

  $emailSubject = 'RailHope email form';

  $emailRecipient = 'liam.johnston@railwaymission.org';

  /* Data variables */

  $firstnameField = $_POST['firstname'];

  $lastnameField = $_POST['lastname'];

  $youremailField = $_POST['youremail'];

  $subjectField = $_POST['subject'];

$body = <<<EOD

<br><hr><br>

firstname: $firstname <br>

lastname: $lastname <br>

youremail: $youremail <br>

subject: $subject <br>

EOD;

  $headers = "From: $youremail\r\n";

  $headers .= "Content-type: text/html\r\n";

  $success = mail($emailRecipient, $emailSubject, $body, $headers);

/* Results renderd as HTML */

  $theResults = <<<EOD

<html>

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>RailHope International</title>

<link href="WebsiteAssets/styles/blogPostStyle.css" rel="stylesheet" type="text/css">

<script>var __adobewebfontsappname__="dreamweaver"</script>

<script src="http://use.edgefonts.net/montserrat:n4:default;source-sans-pro:n2:default.js" type="text/javascript"></script>

</head>

<body><div id="mainwrapper">

  <header>

  

    <div id="logo"><img src="WebsiteAssets/images/RailHope-International-3D-shadow.png" width="198" height="90" alt=""/><!-- <img src="logoImage.png" alt="sample logo"> --><!-- Company Logo text --> </div>

    <nav><a href="index.html"> Home</a> <a href="events.html"> Events</a> <a href="statmentoffaith.html"> Statement of Faith</a> <a href="contact.html" title="Link">Contact</a></nav>

  </header>

  <div id="content">

    <div class="notOnDesktop">

      <!-- This search box is displayed only in mobile and tablet laouts and not in desktop layouts -->

      <input type="text" placeholder="Search">

    </div>

    <section id="mainContent">

   

      <h1>Contact Us</h1>

      <h3>Living Life Through Faith in God</h3>

      <div id="bannerImage"><img src="WebsiteAssets/images/Lunteren-1000-300Crop.png" alt=""/></div>

      <p> </p>

      <aside id="authorInfo">

      

   <p>

   <div class="container">

  <form action="contact.php" method="post" target="_self">

    <label for="fname">First Name</label>

    <input type="text" id="fname" name="firstname" placeholder="Your name..">

    <label for="lname">Last Name</label>

    <input type="text" id="lname" name="lastname" placeholder="Your last name..">

   <label for="lname">Your E-mail</label>

   <input type="text" id="email" name="youremail" placeholder="Your e-mail..">

 

   <textarea id="subject" name="subject" placeholder="Write something.." style="height:200px" ></textarea>

 

 

 

    <input type="submit" value="Submit">

 

 

  </form>

</div>

 

 

 

   </p>

      

      </aside>

    </section>

    <section id="sidebar">

    

      <script async src="https://cse.google.com/cse.js?cx=011950308938588625035:ajfe2qwptc4"></script>

<div class="gcse-search"></div>

      <div id="adimage"><img src="WebsiteAssets/images/300-300Crop-Three-with-train.jpg" alt=""/></div>

      <nav>

        <ul>

         <li><img src="WebsiteAssets/images/Switzerland.jpg" width="27" height="18" alt=""/><a href="switzerland.html" target=""> RailHope Switzerland</a></li>

          <li><img src="WebsiteAssets/images/Germany.png" width="27" height="18" alt=""/><a href="germany.html" target=""> RailHope Germany</a></li>

          <li><img src="WebsiteAssets/images/Austria.jpg" width="27" height="18" alt=""/><a href="austria.html" title="Link"> RailHope Austria</a></li>

   <li><img src="WebsiteAssets/images/America.jpg" width="27" height="18" alt=""/><a href="america.html" title="Link"> RailHope America</a></li>

          <li><img src="WebsiteAssets/images/Estonia.png" width="27" height="18" alt=""/><a href="estonia.html" title="Link"> RailHope Estonia</a></li>

   <li><img src="WebsiteAssets/images/Finland.png" width="27" height="18" alt=""/><a href="finland.html" title="Link"> RailHope Finland</a></li>

          <li><img src="WebsiteAssets/images/India.png" width="27" height="18" alt=""/><a href="india.html" title="Link"> RailHope India</a></li>

          <li><img src="WebsiteAssets/images/Netherlands.png" width="27" height="18" alt=""/><a href="netherlands.html" title="Link"> RailHope Netherlands</a></li>

          <li><img src="WebsiteAssets/images/Norway.png" width="27" height="18" alt=""/><a href="norway.html" title="Link"> RailHope Norway</a></li>

          <li><img src="WebsiteAssets/images/Singapore.png" width="27" height="18" alt=""/><a href="singapore.html" title="Link"> RailHope Singapore</a></li>

          <li><img src="WebsiteAssets/images/South-Africa.png" width="27" height="18" alt=""/><a href="south-africa.html" title="Link"> RailHope South-Africa</a></li>

   <li><img src="WebsiteAssets/images/Great Britain.png" width="27" height="18" alt=""/><a href="greatbritain.html"> Railway Mission</a><a href="Britsh Railway Mission"></a></li>

        </ul>

      </nav>

    </section>

    <footer>

      <!--************************************************************************

    Footer starts here

    ****************************************************************************-->

      <article>

        <h3><a href="board.html"><strong>Board Info</strong></a></h3>

        <p data_temp_dwid="1">The board of RailHope International works is the administrative body of the organisation, the Chair of the Board is the International President: Ulrich Berger</p>

      </article>

      <article>

        <h3><a href="board.html">General Assembly Info</a></h3>

        <p>The highest decision-making body of the IRM is the General Assembly. All present representatives of the national associations are entitlet to vote.</p>

      </article>

    </footer>

  </div>

  <div id="footerbar"><!-- Small footerbar at the bottom --></div>

</div>

</body>

</html>

EOD;

echo "$theResults";

?>

Views

885

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

What is the value of $success after you send, TRUE or FALSE?

I'm assuming this is going to be strengthened before ever using. You never put raw user input data in anything with some kind of sanitization. Also you're going out of your way to echo the content to the user when you could just output the page and sprinkle the PHP where needed to be much easier to debug.

If you find $success === FALSE, you should start by making sure your php.ini has the correct mail values. One quick way is send a test email, like any of the top examples on PHP's mail page: https://www.php.net/manual/en/function.mail.php

If that email works then it's time to look at what all your var values are. Example #5 is sending a simple HTML email, take a look at that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

Thank you Sinious,

I still have no clue, sorry. About 10 years ago I used PHP to create simple forms, but perhaps it has changed since then. It is frustrating that DreamWeaver says there are no errors in the PHP, so I don't know what I need to change.

I have removed the echo, and set the HTML after the closing PHP ?>

"What is the value of $success after you send, TRUE or FALSE?"  I don't know how to set either True or False value. I have tried to add   $success = "TRUE";

I would love a message to say the email has been received but for now I would be happy just to have it send.

There must be a php for dummies book out there!.

Thanks again

<?php

/*subject for RailHope email*/

  $emailSubject = 'RailHope email form';

  $emailRecipient = 'liam.johnston@railwaymission.org';

  /* Data variables */

  $firstnameField = $_POST['firstname'];

  $lastnameField = $_POST['lastname'];

  $youremailField = $_POST['youremail'];

  $subjectField = $_POST['subject'];

  $body = <<<EOD

<br><hr><br>

firstname: $firstname <br>

lastname: $lastname <br>

youremail: $youremail <br>

subject: $subject <br>

  $headers = "From: $youremail\r\n";

  $headers = "Content-type: text/html\r\n";

  $success = mail($emailRecipient, $emailSubject, $body, $headers);

/* Results renderd as HTML */

  $success = "TRUE";

EOD;

?>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

PHP has definitely changed but the real meat and potatoes have remained tried and true. Such as mail() in some ways.

First thing to do is grab any of the "complete" examples to try on your server. If you can't even get those simple emails and this is some kind of local server, I'd consider your php.ini file having the wrong SMTP settings and can't send mail at all. Please let us know if the simple examples on the page linked above work first.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 06, 2019 Aug 06, 2019

Copy link to clipboard

Copied

LATEST

Did you get mail working?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines