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?
Re: Send Email test and Option Explicit
Can we see the code for SendMail function ? :)
Re: Send Email test and Option Explicit
Thanks, but I figured it out. ;)
Re: Send Email test and Option Explicit
Quote:
Originally Posted by
Aelanna
Thanks, but I figured it out. ;)
Can you share the solution ? :)
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. ;)
Re: Send Email test and Option Explicit
Quote:
Originally Posted by
Aelanna
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
....:wave:
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!
Re: Send Email test and Option Explicit
Quote:
Originally Posted by
Aelanna
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 ....:wave: