Results 1 to 9 of 9

Thread: Adding Custom Reply-To email address to a Mailer Form?

  1. #1
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Adding Custom Reply-To email address to a Mailer Form?

    I am trying to customize the Reply-To header when an email is sent out to members of my website.

    Right now, when I send out an email to my members, the reply-to is the same as the from, which is like this:

    from MyWebsite <noreply@mywebsite.com>
    reply-to "noreply@mywebsite.com" <noreply@mywebsite.com>
    I want to change the reply-to address to "mywebsitename@gmail.com"

    The code looks like this:

    Code:
    function sendmail() {
    		$session = $this->session->userdata('adminid');
    	
    		if(empty($session)) {
    				$url = base_url() . 'adminLogin/';
    				redirect($url);
    		}
    		$data['pageTitle'] = 'Send Email';
    		$data['bodyId'] = 'manageuserspage';
    		$data['base'] = base_url();
    		
    			if(isset($_POST['submitted'])) {
    			
    				if(!empty($_POST['em'])) {
    					
    					$em = $_POST['em'];
    					foreach($em as $emv) {
    						$tbl = 'members';
    						$in = array(
    								'email' => $emv
    							);
    						
    						$memid = $this->Get_model->get($tbl, $in);
    						if($this->Get_model->err == true) {
    								foreach($memid as $memidv) {
    									
    									$member = $memidv->member_id;
    								}
    						}			
    						$in = array(
    							'member_id' => $member,
    							'user_email' => $emv,
    							'message' => $_POST['text'],
    							'subject' => $_POST['title']
    						);
    						
    						$tbl = 'sent_emails';
    
    						$this->Insert_model->insert($in, $tbl);
    						
    						if($this->db->affected_rows() > 0) {
    
    							$config['protocol'] = 'mail';
    							$config['mailpath'] = '/usr/sbin/sendmail -t';
    							$config['charset'] = 'iso-8859-1';
    							$config['wordwrap'] = TRUE;
    							$config['mailtype'] = 'html';
    
    							$this->email->initialize($config);
    
    							$from = "Our Team";
    							$subject = $_POST['title'];
    							$msg = $_POST['text'];
    					
    
    							$this->email->from('noreply@mywebsite.com', 'mywebsite');
    							$this->email->to($emv);
    							$this->email->subject($subject);
    							$this->email->message($msg);
    							if ( $this->email->send())
    							{
    								$data['text'][] = 'Email has been sent';
    							} else {
    
    								$data['text'][] = 'Error sending email';
    							}
    
    
    						}
    					
    						
    					}
    				}
    				
    
    				
    				
    
    				
    			}
    Last edited by thelorax; 02-06-2010 at 10:38 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That can't be all of the code driving this, but from what is there the only relevant line is:
    $this->email->from('noreply@mywebsite.com', 'mywebsite');

    so just change that email address and title as you desire.

    I don't know how the class behind all of that actually works, so I'm not sure about reply to: it might be contained within from, or it might be another one you have to set like ...->replyto or any other configuration.
    You'd need to look at the code driving this or at documentation somewhere to know.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    djr33, thank you for your reply. I am having a tough time with this because its not my code, someone else wrote it and I am a complete beginner with PHP programming.

    I can't change the From address because the web hosting company won't allow a form to send if it is not originating from the domain. And I want the Reply-to to be a gmail address.

    I really dont know what my next step is to fix this, if you can give me a hint or some help with this, it would be so much help to me.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The code above ONLY specifies the from address. Either that address is then used for both (in which case you can only choose a single email for BOTH from and reply-to, which is actually logical... I don't see why they are actually separate anyway), OR perhaps it is just not set in the code above and you have to look somewhere else to find where it is set.
    As for a next step, you need to look at the rest of the code and figure out what to do. The answer is not in the code above, unless it is just using the same email for both in which case I don't know how you could fix that except, again, looking at the code behind all of this.

    If it ends up being too much of a problem, you can always just rewrite how the email is generated/sent. It's not that complex a process. Complex classes with operations like above are common, but the 'simple' way is very easy as well:
    mail($to,$subject,$bodytext,$headers);

    That will send an email to $to with the subject $subject and body text $bodytext. $headers will contain additional information like from, reply-to, server info and whatever else you want to include (such as if the email is in html format instead of plain text).
    So you can just write your own fairly easily if the code above is too limited. Remember that you should also verify all input first, if that's handled for you by the existing function.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It was written so that the From address is also the Reply To address.

    Isn't there some line I can add in here:

    Code:
    $this->email->from('noreply@mywebsite.com', 'mywebsite');
    	  $this->email->to($emv);
              $this->email->subject($subject);
    	  $this->email->message($msg);
    	  if ( $this->email->send())
    							{
    to just specify a different Reply To address.

    So when the person receives the email and they hit reply, then they don't have to change the To address from the noreply@mywebsite to
    mywebsite@gmail.com, it just does it automatically.

    I cannot change the From address because the form won't send. Its a rule for this hosting company that any form sending a mail must come from the domain itself.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    No. You cannot add any code there.

    This is not the actual code that sends the email. This is an instance of a class (using Object Oriented Programming) that is based on the code OF that class somewhere else.
    Using a class [$instance->function()] is like using an interface to control a code base somewhere else: it's the control panel, but not the underlying functions. So if the underlying functions don't have an option (if the from is the reply to) then you CANNOT manipulate this with the existing controls.

    As I said, you either need to use a new method or work with the UNDERLYING code. This is just the surface and there is no option here to handle a different reply to email.

    Additionally, if you can access the underlying code, then you can remove the rule that it must come from that domain. That's not a very useful rule because you are not having users input their emails: you're directly putting the email in the code itself: there's no danger of spam, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No i think you are confused, maybe I wasn't clear. The rule that it must send from a domain email address was not created by the programmer for this website. Its a rule that was implemented by the web hosting company itself.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    In that case you can't get around it, but you can still rework the underlying code: don't use that class: use another one or modify the class so it separates from and reply-to.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jan 2010
    Posts
    16
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    If you have the email address with your domain name and hosting why not just set it up with an automatic forward to your Gmail address? That way you don't have to worry about looking through the code, you get the same results, and if your hosting company allows it you can even keep making it look like you are sending from the domain at your website.

    I know with goDaddy I have all my support@mydomain.com come to my owner@mydomain.com but when I reply, using owner@mydomain.com, it is transferred to the support@mydomain.com and appears that I am sending it out of that account.

    It was a simple fix to the problem that you were having.

    If you would rather use the script you are using now you zip all the files that regard to this MailForm and we can take a look at them and see where to input the reply to address.

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
  •