Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Testing PHP

  • 28-04-2011 4:49pm
    #1
    Registered Users, Registered Users 2 Posts: 1,501 ✭✭✭


    Hi,

    I have a webpage (contact.html) that contains a contact form that forwards the entered details to contact.php. I have downloaded Wamp Server - it is running and displayed as 'online'. When i enter the info in contact.html and press submit, however, my .php file simply opens in the browser.

    Perhaps i don't have the server set up correctly, but if it's set up incorrectly i don't know how to remedy this. I just left Wamp server with its default installation values.

    I'd appreciate any help that could be offered. Here is the code:
    <form name="contactform" method="POST" action="contact.php">
    			  <table width="450px">
    				<tr>
    				  <td valign="top">
    					<label for="first_name">First Name *</label>
    				  </td>
    				  <td valign="top">
    					<input type="text" name="first_name" maxlength="50" size="30">
    				  </td>
    				</tr>
    				<tr>
    				  <td valign="top">
    					<label for="last_name">Last Name *</label>
    				  </td>
    				  <td valign="top">
    					<input type="text" name="last_name" maxlength="50" size="30">
    				  </td>
    				</tr>
    				<tr>
    				  <td valign="top">
    					<label for="query">Query *</label>
    				  </td>
    				  <td valign="top">
    					<select name="query">
    						<option value="appointments">Appointments</option>
    						<option value="appointments">General Enquiries</option>
    					</select>
    				  </td>
    				</tr>
    				<tr>
    				  <td valign="top">
    					<label for="email">Email Address *</label>
    				  </td>
    				  <td valign="top">
    					<input type="text" name="email" maxlength="80" size="30">
    				  </td>
    				</tr>
    				<tr>
    				  <td valign="top">
    					<label for="telephone">Telephone Number</label>
    				  </td>
    				  <td valign="top">
    					<input type="text" name="telephone" maxlength="30" size="30">
    				  </td>
    				</tr>
    				<tr>
    				  <td valign="top">
    					<label for="message">Message *</label>
    				  </td>
    				  <td valign="top">
    					<textarea name="message" maxlength="1000" cols="25" rows="6">
    					</textarea>
    				  </td>
    				</tr>
    				<tr>
    				  <td colspan="2" style="text-align:center">
    					<input type="submit" value="Submit"/> 
    					<input type="reset" value="Clear"/>
    				  </td>
    				</tr>
    			  </table>
    			</form>
    

    [PHP]
    <?php
    $field_firstname = $_POST;
    $field_lastname = $_POST;
    $field_email = $_POST;
    $field_query = $_POST;
    $field_message = $_POST;
    $field_telephone = $_POST

    $mail_to = 'xxxx@yahoo.com';
    $subject = $field_query.': Message from a site visitor '.$field_firstname.' '.$field_lastname;

    $body_message .= 'From: '.$field_firsname.$field_lastname."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Telephone: '.$field_telephone."\n";
    $body_message .= 'Enquiry type: '.$field_query."\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. We will contact you shortly.');
    window.location = 'contact.html';
    </script>
    <?php
    }
    else { ?>
    <script language="javascript" type="text/javascript">
    alert('Message failed. Please try again');
    window.location = 'contact.html';
    </script>
    <?php
    }
    ?>
    [/PHP]


Comments

  • Registered Users, Registered Users 2 Posts: 35,524 ✭✭✭✭Gordon


    Did you just open the html file by double clicking it? If so, you need to browse the server location (I'm sure that's incorrect terminology!), best thing to do is to check with the help file how to view/run php files. I, for example, use MAMP, the Mac version and I have to browse to: http://localhost:8888/ to view as if it was a web page.


  • Registered Users, Registered Users 2 Posts: 1,501 ✭✭✭gnolan


    Gordon wrote: »
    Did you just open the html file by double clicking it? If so, you need to browse the server location (I'm sure that's incorrect terminology!), best thing to do is to check with the help file how to view/run php files. I, for example, use MAMP, the Mac version and I have to browse to: http://localhost:8888/ to view as if it was a web page.

    Ah right, got it now. Maybe you can help me with the coding. I should say that i've never done PHP before and know nothing about its structure and syntax.

    When i press the submit button i get the message: " Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\CN Nutrition\contact.php on line 9". I don't know what this means except that there is an error on line:

    [PHP]$mail_to = 'xxxx@yahoo.com';[/PHP]

    EDIT: I've fixed that problem but i'm receiving my 'message failed' notification.


  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    You're missing a ';' on the line before you assign a value to $mail_to.

    If that's no longer a problem what are your e-mail settings? Do you have the server correctly specified and have you supplied credentials if required?

    What happens if you just create a PHP script with just a call to mail() and the same parameters as you pass in in your code above?


  • Registered Users, Registered Users 2 Posts: 1,501 ✭✭✭gnolan


    Malice wrote: »
    You're missing a ';' on the line before you assign a value to $mail_to.

    If that's no longer a problem what are your e-mail settings? Do you have the server correctly specified and have you supplied credentials if required?

    What happens if you just create a PHP script with just a call to mail() and the same parameters as you pass in in your code above?

    I see, i left out that ";". Removing that and a collection of "full-stops" after $body_message and one after $headers.

    That seems to have sorted out most of the problems but like you referred to above, i have received an error message regarding my mail settings: "Warning: mail() [function: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 C:\wamp\www\.........".

    Regarding the script you mention above, i have no experience whatsoever of php; so that sentence doesn't make a lot of sense to me! I'm trying to get this finished simply as a quick fix before i learn the ins and outs of php.


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    You need an SMTP server. Your ISP probably won't even allow you sending emails from your IP anyways. Maybe try connecting to your ISP's SMTP server. This can be set in PHP.INI.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    Okay so you need to configure your e-mail. Do you use GMail? You might be able to use that (see here or here).

    Where are you hosting this application? If it's with Blacknight or someone like that then try contacting them and get them to help you with the mail settings.


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Malice wrote: »
    Okay so you need to configure your e-mail. Do you use GMail? You might be able to use that (see here or here).

    Where are you hosting this application? If it's with Blacknight or someone like that then try contacting them and get them to help you with the mail settings.
    By the looks of it, he's doing everything local on his own machine.


  • Registered Users, Registered Users 2 Posts: 1,501 ✭✭✭gnolan


    Webmonkey wrote: »
    By the looks of it, he's doing everything local on his own machine.

    That's correct Webmonkey, everything is done locally for now.

    @Malice: I'll take a look at those gmail settings and see if it works out for me


  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    Webmonkey wrote: »
    By the looks of it, he's doing everything local on his own machine.
    Duh, sorry you're absolutely right. I managed to gloss over the references to localhost in previous posts.

    gnolan: I'd say have a read of the second link I posted. It specifically mentions WAMP so it should be close to the setup you've got. Look on all this as a useful learning experience. Once you've done it once you'll have no problem doing it again :).


  • Registered Users, Registered Users 2 Posts: 1,501 ✭✭✭gnolan


    Malice wrote: »
    Duh, sorry you're absolutely right. I managed to gloss over the references to localhost in previous posts.

    gnolan: I'd say have a read of the second link I posted. It specifically mentions WAMP so it should be close to the setup you've got. Look on all this as a useful learning experience. Once you've done it once you'll have no problem doing it again :).

    I'll be honest, i'm having an absolutely terrible time doing this!

    So far i've got the following in php.ini:
    smtp_server = smtp.gmail.com
    smtp_port = 25
    auth_username = ------@gmail.com	
    auth_password = --------
    

    Now i think that i have to alter the sendmail_path, currently:
    ;sendmail_path =
    

    I'm told that this is not straightforward on Windows, and i need to download "fakesendmail" and install and mess around with php.ini file again, as well as the httpd.conf file for Apache. All of this and i'm not even sure if the code for my form is correct. For a first dip into php...this sucks!

    I do appreciate the help though.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    The last time I did any PHP setup was for Mantis Bug Tracker a few years ago and I don't recall having any hassle setting up e-mail notifications. The thing is though we had it hosted on an external website so the server details were basically the same as setting up something like Outlook.


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Is there point in putting effort into getting it locally? Will the site be on an external server eventually?


  • Registered Users, Registered Users 2 Posts: 1,501 ✭✭✭gnolan


    Webmonkey wrote: »
    Is there point in putting effort into getting it locally? Will the site be on an external server eventually?

    Perhaps eventually, but not any time in the near future.

    When i was writing the contact form i had no idea that this kind of configuration would be necessary. But if i get it set up once hopefully i won't have to do it again for testing locally.

    And if it's a lot easier when hosted on an external server all the better.


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    gnolan wrote: »
    Perhaps eventually, but not any time in the near future.

    When i was writing the contact form i had no idea that this kind of configuration would be necessary. But if i get it set up once hopefully i won't have to do it again for testing locally.

    And if it's a lot easier when hosted on an external server all the better.
    Yeah, I'd say give a few more searches on google for "PHP mail on WAMP" and give them things a few goes.

    You will have no problem on a proper host as it will have all that set up and ready for you anyways.


  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    gnolan wrote: »
    Now i think that i have to alter the sendmail_path, currently:
    ;sendmail_path =
    
    It reads like this is your stumbling block at the moment. Why do you think you need to change it or at least why do you think it's difficult on Windows?


  • Registered Users, Registered Users 2 Posts: 1,501 ✭✭✭gnolan


    Malice wrote: »
    It reads like this is your stumbling block at the moment. Why do you think you need to change it or at least why do you think it's difficult on Windows?

    I got it, i finally got it!

    I had to download software called fakesendmail, install, and link the executable to the sendmail_path.

    There was also a load of other stuff, like commenting out the smtp settings in php.ini and putting them in sendmail.ini instead. Delighted i've got it all done now, don't want to have to do it again.

    Thanks for the help.


  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    gnolan wrote: »
    I got it, i finally got it!

    I had to download software called fakesendmail, install, and link the executable to the sendmail_path.

    There was also a load of other stuff, like commenting out the smtp settings in php.ini and putting them in sendmail.ini instead. Delighted i've got it all done now, don't want to have to do it again.

    Thanks for the help.
    Sounds like a lot of frustration but I'm glad it's working for you now.


Advertisement