Copyright © 2005-2008 Andrea Tincani

AndreaPHP | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (replace _blank with _top using eregi_replace)Next Topic (smtp server) New Topic New Poll Post Reply
AndreaPHP Forum : PHP General : send mail with PHP
Poster Message
ross96
Level: Protégé

Registered: 01-09-2005
Posts: 8

icon send mail with PHP

How can I sand an email from a PHP script? ...I need to send a mail when users compile a form and then send it

15-11-2005 at 10:10 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 16

icon Re: send mail with PHP

Something like this (this script works at my webhost):


<?
// Places have said to fill in the below items...
// however, when I did, the name in all the fields below were doubled 
// (ie: me@mydomain.com;me@mydomain.com) when received. 
    
$_toEmailAddress "";
    
$_ccEmailAddress "";
    
$_bccEmailAddress "";
    
    
$_subject $_POST"subject" ];
    
$_from $email;
    
    
$message  "Message<br />";

    
$_headers "";
    
$_headers .= "MIME-Version: 1.0\r\n";
    
$_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    
$_headers .= "From: " $email "\r\n";
    
$_headers .= "To: whoever@adomain.com\r\n";
    
$_headers .= "CC: "$email ."\r\n";
    
    
$_headers .= "Reply-To: " $email ."\r\n";
    
$_headers .= "X-Priority: 0\r\n";
    
$_headers .= "X-MSMail-Priority: Normal\r\n";
    
$_headers .= "X-Mailer: name_of_mailer_anything_i_think";
    
    
$mailresponse mail("$_toEmailAddress""$_subject""$message"$_headers);
?>




[Edited by admin on 31-01-2006 at 08:17 AM GMT]

____________________________
Everywhere's Local (pre-release), My company's website

16-11-2005 at 04:10 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
newie_1020
Level: Trainee

Registered: 03-01-2006
Posts: 3

icon Re: send mail with PHP

hey!i'm just starting to learn this php thing..just where exactly do i place those lines of codes?

thanks!

____________________________
basta pinoy,posible!

03-01-2006 at 02:20 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 16

icon Re: send mail with PHP

Just in the php file... or in a file by itself, and called as in a function.

____________________________
Everywhere's Local (pre-release), My company's website

04-01-2006 at 07:56 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
newie_1020
Level: Trainee

Registered: 03-01-2006
Posts: 3

icon Re: send mail with PHP

hi! i still can't figure that one oput. doesn't it use two web pages? can you make me a sample ? just to include email adress, the topic, the message and a check box for "URGENT!" property?thanks.i'm still new,sorry...     thanks a lot!

____________________________
basta pinoy,posible!

31-01-2006 at 05:23 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 16

icon Re: send mail with PHP

As far as how many pages, it could be one, two, or a hundred fifty. It all depends on how you gather information, or display the information.

It all depends on how you're using the code to send a message.  It's "less complex" in a way if it's 2 pages, one to collect the data, the other to send the mail, but it all depends on what you're wanting...

Something like:

<html>
    <head>
        <title>Send E-Mail Test</title>
    </head>
    <body>

<?php
    
if ( isset( $_POST['name'] ) )
        
$name $_POST['name'];

    if ( isset( 
$_POST['email'] ) )
        
$toemail $_POST['email'];

    if ( isset( 
$_POST['type'] ) )
        
$subject $_POST['type'];

    if ( isset( 
$_POST['message'] ) )
        
$message $_POST['message'];

    if ( 
$name != '' && $email != '' // and any other required fields
    
{
        
$fromemail "the_from_email";
        
    
// Now... you either include the code I supplied in the following file
    // wrapped in a function with the parameters as show in the calling function
    // name doesn't have to be the same as the file, it just happens to be here
        
include ( 'mailit.php' );
        
mailit$toemail$fromemail$subject$message);
    
    
// Or you do it similar without a file
        
$_toEmailAddress "";
        
$_ccEmailAddress "";
        
$_bccEmailAddress "";
    
        
$_subject $subject;
        
$_from $fromemail;
    
        
$message  "Info from webform:<br />" $message;

        
$_headers "";
        
$_headers .= "MIME-Version: 1.0\r\n";
        
$_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        
$_headers .= "From: $fromemail\r\n";
        
$_headers .= "To: $toemail\r\n";
        
$_headers .= "CC: $fromemail\r\n";
    
        
$_headers .= "Reply-To: $fromemail\r\n";
        
$_headers .= "X-Priority: 0\r\n";
        
$_headers .= "X-MSMail-Priority: Normal\r\n";
        
$_headers .= "X-Mailer: name_of_mailer_anything_i_think";
    
        
$mailresponse mail("$_toEmailAddress""$_subject""$message"$_headers);        


        echo 
"<p style=\"font-size:larger;\">Thank you for your comments</p>\n";
    }
    else
    {
    
// Display any message to the user about required fields
    // although check to make sure they don't see it before they submit 
    // the form (i.e. no warning of "missing name!" if they never had the chance
    // to enter a name)
?>
        <form action="contactus.phtml" method="post">
            <div style="padding:5px;">
                <p>
                    Your name: 
                    <input type="text" name="name" size="50" value="" />
                </p>
                                    
                <p>
                    Your e-mail address: 
                    <span style="font-size:x-small;">(for a copy of this message &amp; a reply)</span>

                    <br />
                    <input type="text" name="email" size="35" value="" />
                </p>
                                    
                <p>
                    Message is about: 
                    <select name="type">
                        <option value="account">Account issues</option>
                        <option value="report">Reporting a post</option>

                        <option value="web">Website issue</option>
                        <option value="advertising">Advertising</option>
                    </select>
                </p>
                                                                    
                <p>
                    Message: <br />
                    <textarea name="message" cols="50" rows="6"></textarea>

                </p>
                                    
                <p>
                    <input type="submit" name="submit" value="Send Message" />
                </p>
            </div>
        </form>
<?
    
}//end of no data or required fields missing
?>        

    </body>
</html>



____________________________
Everywhere's Local (pre-release), My company's website

31-01-2006 at 11:25 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
newie_1020
Level: Trainee

Registered: 03-01-2006
Posts: 3

icon Re: send mail with PHP

opk thanks,il try decoding that script!   

____________________________
basta pinoy,posible!

09-02-2006 at 06:19 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaPHP Forum : PHP General : send mail with PHP
Previous Topic (replace _blank with _top using eregi_replace)Next Topic (smtp server) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: AndreaVB

Copyright © 2005-2008 Andrea Tincani

Powered by: tForum tForum Edition b0.92p1
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team.