Sending message to email address like yahoomail/google mail? (Email notification-php)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Exequiel
    Contributor
    • Jul 2012
    • 288

    Sending message to email address like yahoomail/google mail? (Email notification-php)

    hello friends, I just want to ask if how i can send a message to any email address like yahoomail/googlemail after i submit the form,

    example emails:
    exezick143@gmai l.com // google mail,
    exezick_85@yaho o.com //yahoo mail

    message to send:
    sender_name has been replied to your message.
    to view it please go to: www.mypage.com/reply_message/ - (this is just a sample link)


    Code:
    public function save_reply()
    {
    	$theuser = $_POST['theuser'];
    	$deskid = $_POST['deskid'];
    	$message_reply = mysql_real_escape_string($_POST['message_reply']);
    			$today = date("m/d/Y h:i:s a");
    			session_start();
    			$files = (isset($_SESSION['uploadedIMG']))?$_SESSION['uploadedIMG']:'';
    			
    			$assigned = mysql_fetch_array(mysql_query("SELECT * FROM across_help_desk WHERE help_desk_id='$deskid'"));
    			
    			$insert_reply = mysql_query("INSERT INTO across_help_confirm_message(help_desk_id,assigned,reply_message,sender,sender_status,message_status,attach,date) VALUES('$deskid','$assigned[assigned]','$message_reply','$theuser','1','1','$files','$today')"); 
    			
    			/*
    				code for sending message to email address.
    				example emails: 
    					exezick143@gmail.com // google mail,
    					exezick_85@yahoo.com //yahoo mail
    				message to send: 
    					sender_name has been replied to your message.
    					to view it please go to: www.mypage.com/reply_message/ - (this is just a sample link)
    			*/
    		
    		if($insert_reply)
    		{
    			$bi = 0;
    			$ass = mysql_query("SELECT * FROM across_help_confirm_message WHERE help_desk_id='$deskid'");
    			$count_help_id = mysql_num_rows($ass);
    			$count_help_id = $count_help_id - 1;
    			while($up_message = mysql_fetch_array($ass))
    			{
    				if($bi < $count_help_id)
    				{
    					$mess_up = mysql_query("UPDATE across_help_confirm_message SET message_status='2' WHERE help_desk_id='$deskid' AND confirm_message_id='$up_message[confirm_message_id]'");
    				}
    				$bi++;
    			
    			}
    			
    			if($mess_up)
    			{
    				echo 1;//successfully send
    			}
    		}
    		else
    		{
    			echo 0;	//not send
    		}
    	}
    any reply is appreciated. . .:) thank you :)
    Attached Files
  • Aurangzeb
    New Member
    • Sep 2013
    • 11

    #2
    The last variation that we will consider is email with attachments. To send an email with attachment we need to use the multipart/mixed MIME type that specifies that mixed types will be included in the email. Moreover, we want to use multipart/alternative MIME type to send both plain-text and HTML version of the email. Have a look at the example:



    Code:
    <?php 
    //define the receiver of the email 
    $to = 'youraddress@example.com'; 
    //define the subject of the email 
    $subject = 'Test email with attachment'; 
    //create a boundary string. It must be unique 
    //so we use the MD5 algorithm to generate a random hash 
    $random_hash = md5(date('r', time())); 
    //define the headers we want passed. Note that they are separated with \r\n 
    $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com"; 
    //add boundary string and mime type specification 
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 
    //read the atachment file contents into a string,
    //encode it with MIME base64,
    //and split it into smaller chunks
    $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); 
    //define the body of the message. 
    ob_start(); //Turn on output buffering 
    ?> 
    --PHP-mixed-<?php echo $random_hash; ?>  
    Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" 
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/plain; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    Hello World!!! 
    This is simple text email message. 
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    <h2>Hello World!</h2> 
    <p>This is something with <b>HTML</b> formatting.</p> 
    
    --PHP-alt-<?php echo $random_hash; ?>-- 
    
    --PHP-mixed-<?php echo $random_hash; ?>  
    Content-Type: application/zip; name="attachment.zip"  
    Content-Transfer-Encoding: base64  
    Content-Disposition: attachment  
    
    <?php echo $attachment; ?> 
    --PHP-mixed-<?php echo $random_hash; ?>-- 
    
    <?php 
    //copy current buffer contents into $message variable and delete current output buffer 
    $message = ob_get_clean(); 
    //send the email 
    $mail_sent = @mail( $to, $subject, $message, $headers ); 
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed"; 
    ?>

    As you can see, sending an email with attachment is easy to accomplish. In the preceding example we have multipart/mixed MIME type, and inside it we have multipart/alternative MIME type that specifies two versions of the email. To include an attachment to our message, we read the data from the specified file into a string, encode it with base64, split it in smaller chunks to make sure that it matches the MIME specifications and then include it as an attachment.

    Comment

    • Aurangzeb
      New Member
      • Sep 2013
      • 11

      #3
      you can do more than it.. just follow the link..

      Comment

      • Exequiel
        Contributor
        • Jul 2012
        • 288

        #4
        I used this codes for code igniter, but it still doesn't work. . the link that youve gave is cool, but it still doest work when i tried it. . thank you for the reply Aurangzeb :)

        $this->load->library('email ');
        $this->email->from('across.p h');
        $this->email->to("exezick143 @gmail.com");
        $this->email->subject('subje ct');
        $this->email->message('sende r_name has been replied to your message.');
        $this->email->send();

        Comment

        • Aurangzeb
          New Member
          • Sep 2013
          • 11

          #5
          your welcome bro...:p

          Comment

          Working...