MUSAlist   MissyUSA¼îÇθô
·Î°í  
 
»ýÈ° Q & A

À¥»çÀÌÆ®°ü·Ã) php ½ºÅ©¸³Æ® ÀÐÀ¸½ÇÁپƽôºÐ...?
76.--.69.96 2012-1-13 (07:11:51)
Á¦°¡ Á¦ À¥»çÀÌÆ®¸¦¸¸µå´Â ÁßÀε¥..
contact ÆäÀÌÁö¿¡¼­ ÀÌÁ¦ »ó´ë¹æÀÌ 

À̸§, À̸ÞÀÏÁÖ¼Ò, ±×¸®°í ³»¿ëÀ»¾²°í send ¹öÆ°À»´©¸£¸é ÀúÇÑÅ× À̸ÞÀÏÀÌ ¿À°Ô¸¸µé°í½Í°Åµç¿ä
Á¦°¡ html ÅÆÇ÷¿Àº ¾î¶²À¥»çÀÌÆ®¿¡¼­ »ò°í... °Å±â¿¡ÀÌÁ¦ 

contact.html ÆÄÀÏÀÌÀÖ°í 
sendmail.php ÆÄÀÏÀÌÀִµ¥ 

sendmail.php ÆÄÀÏÀ» ¼öÁ¤ÇØ¾ß ÀúÇÑÅ× À̸ÞÀÏÀÌ¿À°ÔÇÒ¼öÀִ°Ͱ°Àºµ¥ 

½ºÅ©¸³Æ®°¡ ¿ä¹Ø¿¡ ÀÌ·¸°Ô»ý°å´Âµ¥..

´ëü ¹» ¼öÁ¤ÇØ¾ß ÀúÇÑÅ׿üöÀÖ°ÔÇÒ¼öÀִ°ÇÁö ¤Ð¤Ð¤Ð

¼¼¹ø¤Š¶óÀκ¸¸é define the from email À̶ó°íÇسùÀݾƿä..   ±×·³ 

FROM_EMAIL ¿¡ÀÖ´Â 'info@test.it' À» Á¦ À̸á·Î¹Ù²Ù¸éµÇ´Â°Ç°¡¿ä? 
TO_EMAIL ¿¡ ¾ÈÅä´Ï¿À.. Àú°Ç ¹ºÁö..? 

´ëü ¹» ¼öÁ¤ÇؾߵǴÂÁö¸ð¸£°Ú¾î¿ä... Èæ 

<?php

/**
 * Define the from email
 */ 
 
// email
define('TO_EMAIL', 'antonino.scarfi@gmail.com') 
define('FROM_EMAIL', 'info@test.it')  
define('FROM_NAME', 'Test') 

/**
 * define the body of the email. You can add some shortcode, with this format: %ID%
 * 
 * ID = the id have you insert on the html markup.
 * 
 * e.g.
 * <input type="text" name="email" />
 *       
 * You can add on BODY, this:
 * email: %email%   
 */ 
define( 'BODY', '%message%<br /><br /><small>email inviata da %name%, email %email%.</small>' )
define( 'SUBJECT', 'Email from yoursite.com' )

// here the redirect, when the form is submitted
define( 'ERROR_URL', 'contatti_error.php' )
define( 'SUCCESS_URL', 'contatti_success.php' ) 
define( 'NOTSENT_URL', 'contatti_notsent.php' )           

// the message feedback of ajax request
$msg = array(
    'error' => '<p class="error">Warning! Fill correctly the fields marked in red</p>',
    'success' => '<p class="success">Email sent correctly. Thanks to get in touch us!</p>',
    'not-sent' => '<p class="error">An error has been encountered. Please try again.</p>'
)      
    
// the field required, by name
$required = array( 'name', 'email', 'message' )

/**
 * Send the email.
 * 
 * SERVER-SIDE: the functions redirect to some URL, in base of result of control and send.
 * The urls must be set in the constants above: ERROR_URL, SUCCESS_URL, NOTSENT_URL
 * 
 * CLIENT-SIDE: in js/contact.js, there is already script for real-time checking of fields
 * and for ajax request of send email, that request in this page (sendmail.php) and echo the feedback message.    
 */   
sendemail()
    
// NO NEED EDIT
function sendemail() 
{
    global $msg, $required
    
    if ( isset( $_POST['ajax'] ) )
        $ajax = $_POST['ajax']
    else
        $ajax = false
    
if ( isset( $_POST['action'] ) AND $_POST['action'] == 'sendmail' ) 
{
   $body = BODY
   
   $post_data = array_map( 'stripslashes', $_POST )
   
//    print_r($post_data)
//    die
   
   foreach ( $required as $id_field ) {
       if( $post_data[$id_field] == '' || is_null( $post_data[$id_field] ) ) {
           if ( $ajax )
              end_ajax( $msg['error'] )
           else
          redirect( ERROR_URL )
       }                       
    }
   
   if( !is_email( $post_data['email'] ) OR $post_data['email'] == '' ) 
       if ( $ajax )
          end_ajax( $msg['error'] )
       else
          redirect( ERROR_URL )
   
   foreach( $post_data as $id => $var )
   {
    if( $id == 'message' ) $var = nl2br($var)
$body = str_replace( "%$id%", $var, $body )
}
   
$headers  = 'MIME-Version: 1.0' . "

"
$headers .= 'Content-type: text/html charset=UTF-8' . "

"
$headers .= 'From: '.FROM_NAME.' <'.FROM_EMAIL.'>' . "

" . 'Reply-To: ' . $post_data['email']
   $sendmail = mail( TO_EMAIL, SUBJECT, $body, $headers )
        
if ( $sendmail ) 
       if ( $ajax )
          end_ajax( $msg['success'] )
       else
          redirect( SUCCESS_URL )
   else
       if ( $ajax )
          end_ajax( $msg['not-sent'] )
       else
          redirect( NOTSENT_URL )
}

function is_email($email) 
{
    if (!preg_match("/[a-z0-9][_.a-z0-9-]+@([a-z0-9][0-9a-z-]+.)+([a-z]{2,4})/" , $email))
    {
        return false
    }
    else
    {
        return true
    }
}             

function end_ajax( $msg = '' ) {
    echo $msg
    die
}           

function redirect( $redirect = '' ) {
    header( 'Location: ' . $redirect )
    die
}      

?>

 
 
Àü¹®°¡ Ä®·³
°øÁö»çÇ× : 2024³â6¿ù19ÀÏ ¹Ì¾¾USA ¼­¹öÁ¡°Ë
·Î°í »çÀÌÆ®¼Ò°³ | ¼­ºñ½º¾à°ü | °ÇÀÇ/¿¡·¯½Å°í | Á¤È¸¿øµî¾÷¾È³» | ±¤°í¹®ÀÇ