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

Can php allow a user to be sent a mail on a Website

Options
  • 22-06-2012 3:55pm
    #1
    Registered Users Posts: 14


    Hi All,

    I am looking for some script or a starting point to find some. I have a website that I need to allow a users to enter their details in to a form:

    Example:

    Name:
    Email:

    Submit

    When the user enters the details and hits submit they are sent an email with an attached file to the email address that they have entered on the page. Can anybody please tell me if this can be done with just php or do I need a sql database also? I am quite limited in web design (self taught) so keeping it easy is what I am looking for

    If that is not a runner, what about .cgi (know very little about this).

    The attached file is a vCard and the page will inform the user that this is what they will receive by mail.

    As always thanks in advance to anyone who can help,

    Best regards,
    Caben


Comments

  • Registered Users Posts: 1,144 ✭✭✭Ballyv24


    http://www.w3schools.com/php/php_mail.asp

    This is a good intro example. What do you mean you want an attached file?


  • Registered Users Posts: 14 Caben


    Ballyv24 wrote: »
    What do you mean you want an attached file?

    The user needs to receive an email with a vCard attached to it when they click submit.

    Thanks
    Caben


  • Registered Users Posts: 14 Caben


    Ballyv24

    Thanks for the link, but on review this only sends a text message to a specified e-mail address

    I need it to use the email address submitted by the user.

    I am 99% sure you and others understand what I mean, but this should clear everything up.

    Example:

    User goes to www.123.ie
    User enters test@test.ie to the email form box and clicks submit.
    User receives an email from no-reply@123.ie, with a vCard attached to the email, to their account test@test.ie

    Again thank in advance
    Caben


  • Registered Users Posts: 1,477 ✭✭✭azzeretti


    Caben wrote: »
    Ballyv24

    Thanks for the link, but on review this only sends a text message to a specified e-mail address

    I need it to use the email address submitted by the user.

    I am 99% sure you and others understand what I mean, but this should clear everything up.

    Example:

    User goes to www.123.ie
    User enters test@test.ie to the email form box and clicks submit.
    User receives an email from no-reply@123.ie, with a vCard attached to the email, to their account test@test.ie

    Again thank in advance
    Caben

    There are many ways to do this. Firstly, you need to get the form information into a function of some sorts by posting it - are you familiar with simple web forms? If so, set it up to post your details to another page (or the same page) where variables are then used to send the mail.

    Once there you can use a multitude of modules/libraries to send the email. Unfortunately (for you!) I know very little PHP. However, if you were using Perl you could use many of the modules available on CPAN to either relay the mail through an external mail server (GMAIL etc) or send it out through a local mail server (do you have access to either from your website?) Pear should have similar module for PHP and I'd imagine it's as simple in PHP as it would be in Perl.

    Here is a quick and nasty Perl script (I tested it and it works from my PC with Exim running - however, you would need to change it a good bit (only send mail if $email is defined etc.) in production but it should get you started) Also, you'll need to get MIME::Lite to make it work - also, change the $attachment path to include the business card to send

    The PHP guys will come along soon and help you out with that alternative too.
    #!/usr/bin/perl
    
    use strict;
    use MIME::Lite;
    use CGI;
    print "Content-type: text/html\n\n";
    
    my $cgi = new CGI;
    my $email_address = $cgi->param('email_address');
    my $name = $cgi->param('name');
    my $attachment = "/tmp/test.pdf";
    
    print "$email_address $name <br/>";
    
    print "<form name='email' method='post' action='email.pl'>
    <label for='email_address'>Email Address:<input type='text' name='email_address' id='email_address'>
    <label for='name'>Name:<input type='text' name='name' id='name'>
    <br />
    <input type='submit' value='Email me'>
    ";
    
    my $msg = MIME::Lite->new(
            From    => "sending\@address.com",
            To      => "$email_address",
            Subject =>  "Your business card",
            Type    => 'multipart/mixed'
        );
    
    
    
    $msg->attach(
            Type     => 'TEXT',
            Data     => "Dear $name, Attached is business card.\n\nRegards,\nJohn Smith"
        );
    
    $msg->attach(
            Type    => 'application/pdf',
            Data    => $attachment,
            Filename => $attachment,
            Disposition => 'attachment'
        );
    
    $msg->send('smtp','localhost', Debug=>1 );
    
    


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    What you're looking for is a script that:
    1. Takes in an email address and name as inputs.
    2. Generates a vCard based upon the above.
    3. Emails the above email with the vCard attached.
    4. Terminates gracefully (shows or forwards to a landing page).
    You cannot program, otherwise what you've been given would already be sufficient, so you need a ready made script that requires a minimum of configuration.

    TBH, you didn't search too hard before coming here - took me all of 1 minute to find something that you might be able to use, although it may still require small coding modifications (which you may not be able to do). Let me introduce you to Google.

    Please tell me you've no association with 123.ie


  • Advertisement
  • Registered Users Posts: 45 irishd


    As regards the code, the PEAR extensions include functions for mailing MIME attachments, and a quick google for "PHP vCard Library" will return anything else you need. Actually, I think CodeIgniter contains support for both.

    Just to add.... if you are sending to a user-entered email address, then you absolutely need to use a captcha or similar method to prevent automated submission of the form, otherwise it can be easily abused. Also,make sure to do plenty of sanitizing of variables in your script, otherwise unscrupulous people could abuse the script to send malformed vCards, spam, etc.


  • Registered Users Posts: 14 Caben


    Genuinely want to say thanks for the help. I will look into the details of the script over the next while. I know it is a year later but thanks. I went off the boil with the idea I had but I will see if this will work. Sorry for the delay (better late than never).

    Caben


Advertisement