SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How/where do you put an email reference/tag in php?

    How/where do you put an email reference/tag in php/jquery/html?

    I have a contact form on my website, but don't know to set it up... it's a template website, and it looks good... but I only have some html knowledge. No idea about php or jquery.

    Thanks.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've not provided nearly enough information! For a start we could really do with knowing the source code you're working with...

    If you're just after a simple email link on a web page then this will do it:
    Code:
    <a href="you@your_domain.com">email me!</a>
    I suspect however that you're trying to make a template form magically send email. The form may be designed in html but its no good without a script on the server to process it. When you submit a form, your browser (Internet explorer, firefox, netscape etc) submits the data in the form back to a script on the server which then handles the data and does what ever the script is designed to do with it - EG write it to a database, email it, etc.

    I suspect you're missing this!

    Perhaps if you could post a URL to your form, or show us some source code from the site we might be able to help further.

    Regards

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi tangoforce. Thanks for your message. I'm familiar with the html tag, but this is different. I don't know how to explain it... let me try...

    I have a contact page here... http://1and1websolutions.co.uk/contact.html

    Behind that page is two documents... contact.html and contact.php

    First unfamiliar thing: there's a jquery section in the html document
    Second unfamiliar thing: the php document - I never worked with php before...

    I don't know where to put the email so the form gets sent to my email... in the jquery section, in the php or the html... or all three? And exactly where?

    I've tried lots of things... looked online and copy-pasted... tried and tried... I'll get the answer eventually... but for now, it's a mystery.

  4. #4
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firstly I've never touched jquery so I'm not sure if its using AJAX and submitting the form and receiving a response or whether the entire page is submitted and refreshed.

    The email address however should be set within the php file.

    Look for a line containing the mail() function (search for 'mail(' in your editor - miss off the last ')' as it will have parameters). Look at the first parameter and replace it.

    Should be something like..
    Code:
    mail('user@domain.com', 'subject', 'message');
    By the way the layout of your page is a bit iffy. I'm using seamonkey and it's not displaying correctly meaning that it won't in firefox either. The email box is over on the right where the other text is! Use browsershots.org for testing in this respect as it will show you how your site looks on multiple browsers.

    No more replies from me now as I'm off to bed (3:11am) so someone else will have to help from here...

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! I never knew there were so many browsers! Good web link. Thanks... I've heard of SeaMonkey but I just absent-mindedly clicked to check the page on about a million browsers... didn't check for SeaMonkey though... I'm knackered as well... will try your suggestion later, let you know how I get on. Thanks for the tip.

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    contact.html is just a still interface to collect the data. If the user has JS enabled then the jQuery on the page will hijack the form submission and post the data to contact.php using Ajax. The form will be updated with a success message without reloading the page.

    If JS is disabled the form will submit the old fashioned way (page reload), also to contact.php

    Either way contact.php receives POST data ($_POST) and that script will send the email.

    As tangoforce mentioned you'll need to look at contact.php to find out where to set YOUR email address to receive the submissions. There will probably be a configuration variable that you change for that purpose.

    contact.php should be the only script you need to modify. It's also possible that it calls a separate config file that defines this paramater.

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi cranial-bore... great name. Er, I've tried different things on the contact.php document with no success. The jquery is on the contact.html document. Maybe I should try messing with that. I would copy-paste the entire code here, but I'm not sure if I'm allowed... I'll show you a bit of the contact.php document... MY OWN COMMENTS ARE IN CAPS...

    if($errors==1) echo $error;
    else{
    $values = array ('name','email','message');
    $required = array('name','email','message');

    $your_email = "john@example.com"; // THIS IS WHERE I THOUGHT MY EMAIL SHOULD BE AND I TRIED - FAILED
    $email_subject = "New Message: ".$_POST['subject'];
    $email_content = "new message:\n";

    foreach($values as $key => $value){
    if(in_array($value,$required)){
    if ($key != 'subject' && $key != 'company') {
    if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
    }
    $email_content .= $value.': '.$_POST[$value]."\n";
    }
    }

    if(@mail($your_email,$email_subject,$email_content)) { // <<THIS IS WHERE I THOUGHT MY EMAIL SHOULD BE AND I TRIED - FAILED. NOT EXACTLY SURE WHERE TO PUT IT...
    echo 'Message sent!';
    } else {
    echo 'ERROR!';

  8. #8
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THIS IS THE JQUERY FORM (which is on the contact.html document) - I HAVE NO IDEA WHAT TO DO WITH IT.......

    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
    // <![CDATA[
    jQuery(document).ready(function(){
    $('#contactform').submit(function(){
    var action = $(this).attr('action');
    $.post(action, {
    name: $('#name').val(),
    email: $('#email').val(),
    company: $('#company').val(),
    subject: $('#subject').val(),
    message: $('#message').val()
    },
    function(data){
    $('#contactform #submit').attr('disabled','');
    $('.response').remove();
    $('#contactform').before('<p class="response">'+data+'</p>');
    $('.response').slideDown();
    if(data=='Message sent!') $('#contactform').slideUp();
    }
    );
    return false;
    });
    });
    // ]]>
    </script>

  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    Update (the php part) to:
    PHP Code:
    if(@mail($your_email,$email_subject,$email_content,"From: name@website-name.com\r\n")){
    echo 
    'Message sent!'

    where website-name.com is the website on which you are running this script

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks prasanthmj... I tried, but it's still not working.

    I suspect tangoforce ^^ is correct - I need to put something on the server to make it work... but which part? Which script?

    I don't have direct access to the server. I can ask my host to give me temporary access... but I need to know what to do first, I guess...

  11. #11
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get rid of the @ in if(@mail(...
    It suppresses errors which is not helpful for debugging.

    $your_email is the variable to edit. If that's not working check your spam/junk folder.
    Try a few different email addresses.

    If none of that works the PHP mail function might not work on your server. Test by creating a new separate script with this code, uploading it, and executing it in your browser:
    PHP Code:
    $to 'me@example.com'//put your address here

    if(mail($to'Test Email from Server'"Congratulations, you made it.\r\n" date('r'))) {
      echo 
    "Mail sent";
    }
    else echo 
    "Error"

  12. #12
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amonta View Post
    Thanks prasanthmj
    I suspect tangoforce ^^ is correct - I need to put something on the server to make it work... but which part? Which script?
    Nope, I'm not correct as you have the php file I was talking about and you've even posted the source

    I suspect that sendmail might not be enabled on your account because from what I can see that code should work.

    As cranial has said, remove the '@' from the (@mail( line and php should throw up some errors to let you know whats wrong.

  13. #13
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't believe it – I THINK IT JUST WORKED!!!!!!!!!!!!!!!!!!!

    WHOAAAAAAAAAYYYYYYYYYAAAAAAAAAAAAAYYYYYYYYYYY!!!!!!!!!

    Will test after a cigarette, don't want to spoil the moment...

    Thanks for all your help - will update you. But I think it did work... I'll try it again a few times...

    I think it was just a case of taking out the @ sign... and putting in the email here...

    $your_email = info@1and1websolutions.co.uk // <<< HERE

    and then taking out the @ from @mail further down...

    I can't believe it... Thanks again...

    Will post later...

    Bye for now

  14. #14
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great stuff!

    Keep us posted

  15. #15
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I owe you people a big thank you... the form seems to work, and I've updated the template/site and things seem ok...

    Not sure what else I can offer you by way of gratitude – free web hosting, if you like... or maybe you can be among my first web design customers? A dubious offer, you might say, but we all have to start somewhere. And I'm not that bad really - I got good taste/understanding and some skills... php and jquery and a few other things are a bit new to me though...

    If you have a moment, you're invited/welcome to visit the site and let me know what you think... good or bad. http://1and1websolutions.co.uk – I'll be spending a bit of money advertising it from Monday... hope that works.

    And if you do know anyone who wants a freebie - web design and web hosting - you could let them know they can be among my first/test customers.

    Now I know how this form works, hopefully many of my templates will not be so intimidating any more. I guess the next challenge will be to learn how the search works... hope you guys are around for that...

    Thanks again... See you around...

  16. #16
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Certainly a glitzy looking site!

    No worries about the gratitude thing, thats why we people use this forum - to exchange ideas, ask questions and help people

    Glad you got it working!

  17. #17
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah it's quite an attractive design... I hope it works. Thanks.

  18. #18
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amonta View Post
    $your_email = info@1and1websolutions.co.uk // <<< HERE
    Just for completeness - use quotes around your eMail address.
    Strings in PHP have to be quoted, otherwise they are seen as constants - which would be wrong in this case.

    So it should read:
    PHP Code:
    $your_email 'info@1and1websolutions.co.uk'


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •