Results 1 to 8 of 8

Thread: Send Email test and Option Explicit

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Send Email test and Option Explicit

    I have a simple .asp page set up to test the functionality of the email sending on my web server. The code is below:

    Code:
    <% @ Language=VBScript %>
    
    <!--#include file="includes/functions_send_mail.asp" -->
    <%
        Response.Expires=0
        Response.ExpiresAbsolute =now()-1
        Response.AddHeader "pragma","no-cache"
        Response.AddHeader "cache-control","private"
        Response.CacheControl ="no-cache"
    
        'Declare variables
        Dim strEmailBody		'Holds the body of the e-mail message
        Dim strRecipname 		'Holds the Username of the recipient
        Dim strRecipEmail		'Holds the email address of the recipient
        Dim strSendername		'Holds the name of the sender
        Dim strSenderEmail		'Holds the email address of the sender
        Dim strSubject 			'Holds the subject of the email
        Dim strMailComponent
        Dim blnEmailSent		'set to true if an e-mail is sent
    
            	
        'Set up email
        strRecipname = "Recipient"
        strRecipEmail = "[email protected]"
        strSendername = "Sender"
        strSenderEmail = "[email protected]"
        strSubject = "Test Email function"
        strMailComponent = "CDOSYS"
        strEmailBody = "Hello Recipient,<br>This is a test email. So, please ignore.<br><br>Thanks"
        
        'Call the function to send the e-mail
        blnEmailSent = SendMail(strEmailBody, strRecipname, strRecipEmail, strSendername, strSenderEmail, strSubject, strMailComponent, true)
       
    %>
    <html>
    
    <head>
        <title>Test Email</title>
    </head>
    <body>
        Email sent successfully! <%=blnEmailSent %>
    </body>
    </html>
    The variable blnEmailSent is supposed to be True if the email was successfully sent, and False if not. But in practice, here's what happens. The page reports email sent True, but I never receive any email. (I have changed the email addresses in the code to protect the innocent )

    If, however, I add the line <% Option Explicit %> after the Language line, the page reports email sent False, but I DO get the email. Can someone explain to me why this works in reverse, and why that line makes any difference?

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Send Email test and Option Explicit

    Can we see the code for SendMail function ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: Send Email test and Option Explicit

    Thanks, but I figured it out.

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Send Email test and Option Explicit

    Quote Originally Posted by Aelanna View Post
    Thanks, but I figured it out.
    Can you share the solution ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: Send Email test and Option Explicit

    Well, I don't really understand it all myself... A programmer friend of mine figured it out. He said it had to do with the use of Option Explicit in some pages but not others, and it wasn't needed. There was an If statement that was checking for success of the mail sending function in reverse. So... it's all working now and I'm happy.

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Send Email test and Option Explicit

    Quote Originally Posted by Aelanna View Post
    Well, I don't really understand it all myself... A programmer friend of mine figured it out. He said it had to do with the use of Option Explicit in some pages but not others, and it wasn't needed. There was an If statement that was checking for success of the mail sending function in reverse. So... it's all working now and I'm happy.
    Glad to hear that it is sorted out...

    An article you might need to read: http://www.vbforums.com/showthread.php?t=461140
    ....

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: Send Email test and Option Explicit

    I wish I had seen this article sooner. I did a search or that term on here, but didn't see that one. Thank you!

  8. #8
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Send Email test and Option Explicit

    Quote Originally Posted by Aelanna View Post
    I wish I had seen this article sooner. I did a search or that term on here, but didn't see that one. Thank you!


    Complete VB6 FAQ: http://www.vbforums.com/showthread.php?t=348141 ....

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width