getting Fatal error: Uncaught exception 'Swift_RfcComplianceException'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neovantage
    New Member
    • Aug 2008
    • 245

    getting Fatal error: Uncaught exception 'Swift_RfcComplianceException'

    Hey all,
    I am using Swift mailer and i am getting error

    "Fatal error: Uncaught exception 'Swift_RfcCompl ianceException' with message 'Address in mailbox given [0] does not comply with RFC 2822, 3.6.2.' " while sending email through swift Mailer. Can some body tell me what is the reason behind of getting this error and how can i fix that error. I will be very thankful to him/her for solving my problem as my work stop due to this error

    kind regards,
    Mohsin Rafique
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    first, which Swift version are you using (Swift 4.0 was recently published)?

    to prevent an uncaught Exception you need to enclose your code in a try-catch block
    Code:
    try {
        // your code
    }
    catch (Exception $e)
    {
        // fallback code here
    }
    or use a default Exception handler (set_exception_h andler()).

    the Exception states that either the From, Sender or Reply-To header does not adhere to the standard (see RFC 2822). I need to see the code of that to tell you more.

    regards

    Comment

    • neovantage
      New Member
      • Aug 2008
      • 245

      #3
      First of all Thank you for your reply.
      Well sir i recently download the swift mailer script 4 days ago and i am not sure which version is this. But here is my code sir

      Code:
      require_once 'lib/swift_required.php';
      			$transport = Swift_MailTransport::newInstance();
      			//Create the Mailer using your created Transport
      			$mailer = Swift_Mailer::newInstance($transport);
      			$message = Swift_Message::newInstance()
      			//Give the message a subject
      			->setSubject('One Owner Car Password Reset Confirmation')
      			
      			//Set the To addresses with an associative array
      			->setTo(array($email => $customer_name))
      			//->setTo(array('mohsin.rafique@ewconsultinginc.com' => 'Louise'))
      			
      			//Set the From address with an associative array
        			->setFrom(array($from => $from_name))
        			
      			//A Sender: address specifies who sent the message and is set with the setSender() method of the message.
      			->setSender($no_reply)
      			
      			//The Return-Path: address specifies where bounce notifications should be sent and is set with the setReturnPath() method of the message.
      			->setReturnPath($bounce)
      			
      			//Set Priority 1=Highest, 2=High, 3=Normal, 4=Low, 5=Lowest
      			->setPriority(2)
      			
      			//Give it a body
      	 	 	->setBody('
      			<table cellspacing="0" cellpadding="0" border="0" align="left" width="570" style="font-family:Arial;font-size:12px;color:#000000;">
      				<tr><td><font style="font-size:18px;font-weight:bold;">Hey '.$customer_name.'</font></td></tr>
      				<tr><td>&nbsp;</td></tr>
      				<tr>
                      	<td>
                          You recently requested a new password.  To reset your password, follow the link below:<br />
                          <a href="'.PATH_WEB.'reset.php?sid='.$sid.'&amp;cid='.$cid.'" style="text-decoration:none; color:#333333;">'.PATH_WEB.'reset.php?sid='.$sid.'&amp;cid='.$cid.'</a><br /><br />
                          <em>(If clicking on the link doesn&acute;t work, try copying and pasting it into your browser.)</em><br />
                          Please do not close your browser until the password page completely loads, which may take several minutes.<br /><br />
                          If you did not reset your password, please disregard this message.
                   		</td>
                     	</tr>
                      <tr><td style="border-bottom:1px dashed #333333;">&nbsp;</td></tr>
      				<tr><td>Please do not reply to this email, as this mailbox is not monitored.<br />Thanks<br /><a href="http://www.oneownercar.com.au">One Owner Car Team</a></td></tr>
      			</table>
      			', 'text/html')
      			;
      			if ($mailer->send($message)){
      				echo "
      				<form name='forgotForm' id='forgotForm' method='post' action='reset.php'>
      					<input type='hidden' name='confirmation' id='confirmation' value='done' />
      					<input type='hidden' name='email_confirmation' id='email_confirmation' value='".$email."' />
      					<input type='submit' style='visibility:hidden' />
      				</form>
      				<script type='text/javascript'>document.forgotForm.submit();</script>
      				";
      				exit();
      			}else{
      				echo "
      				<form name='forgotForm' id='forgotForm' method='post' action='reset.php'>
      					<input type='hidden' name='confirmation' id='confirmation' value='Error sending email' />
      					<input type='submit' style='visibility:hidden' />
      				</form>
      				<script type='text/javascript'>document.forgotForm.submit();</script>
      				";
      				exit();
      			}

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        are you sure that $from, $no_reply and $bounce are correctly set?

        to get more info from the Exception try
        Code:
        try {
            // swift code
        }
        catch (Exception $e)
        {
            echo $e->getTraceAsString();
        }

        Comment

        • neovantage
          New Member
          • Aug 2008
          • 245

          #5
          Thanks again sir! It fixed automatically without using try catch block

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            good. but you should load a default exception handler, you never know when the next Exception will be thrown.

            Comment

            Working...